У меня есть простой TableView с базовыми ячейками стиля.Я заполняю его следующим образом:
class MunicipalitiesViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate {
var municipalities = [Municipality]()
@IBOutlet weak var municipalitiesTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
let dbHelper = RaccoltacaseDbHelper()
municipalities = dbHelper.getMunicipalities()
municipalitiesTableView.dataSource = self
municipalitiesTableView.delegate = self
}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
filterMunicipalities(s: searchText)
self.municipalitiesTableView.reloadData()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.municipalities.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath)
var municipality = Municipality()
cell.textLabel?.text = municipality.value!
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let filterVC = storyboard?.instantiateViewController(withIdentifier: "FilterViewController") as! FilterViewController
var municipality = Municipality()
if municipalitiesSearchBar.text != "" {
municipality = filteredMunicipalities[indexPath.row]
}
else {
municipality = municipalities[indexPath.row]
}
let search = Search()
if (municipality.id == 0) {
search.zoneId = municipality.province
search.isMunicipality = false
}
else {
search.zoneId = municipality.id
search.isMunicipality = true
}
search.type = Search.ZONE_TAG
filterVC.search = search
self.navigationController?.pushViewController(filterVC, animated: true)
}
}
Теперь, когда я нажимаю на строку, все работает, как ожидаетсяно если я нажимаю на приложение разделения ячеек, происходит сбой со следующей ошибкой: Завершение приложения из-за необработанного исключения «CALayerInvalid», причина: «слой является частью цикла в его дереве слоев»
Что я делаю неправильно?