falha ao obter uma célula de seu dataSource com swift 3
Eu tenho o UITableViewController abaixo anexado como um searchResultsController:
import UIKit
import MapKit
class LocationSearchTable : UITableViewController {
var matchingItems:[MKMapItem] = []
var mapView: MKMapView? = nil
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
}
}
extension LocationSearchTable : UISearchResultsUpdating {
func updateSearchResults(for searchController: UISearchController){
guard let mapView = mapView,
let searchBarText = searchController.searchBar.text else { return }
let request = MKLocalSearchRequest()
request.naturalLanguageQuery = searchBarText
request.region = mapView.region
let search = MKLocalSearch(request: request)
search.start { response, _ in
guard let response = response else {
return
}
self.matchingItems = response.mapItems
self.tableView.reloadData()
}
}
}
extension LocationSearchTable {
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print(matchingItems.count)
return matchingItems.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")!
let selectedItem = matchingItems[indexPath.row].placemark
cell.textLabel?.text = selectedItem.name
cell.detailTextLabel?.text = ""
return cell
}
}
Aqui ele caiu uma vezmatchingItems.count
não é igual a 0, por exemplo:
0 0 10-20-10 de 2016 15: 43: 53.914 ios-App [9137: 977735]* Falha de asserção em - [UITableView _configureCellForDisplay: forIndexPath:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3599.6/UITableView.m:8035 20/10/2016 15: 43: 53.927 ios Aplicativo [9137: 977735] * Finalizando o aplicativo devido à exceção não capturada 'NSInternalInconsistencyException', motivo: 'UITableView (; layer =; contentOffset: {0, -64}; contentSize: {768, 440}>) falhou ao obter uma célula de seus dados
Quando adiciono pontos de depuração no cellForRowAtIndexPath, eles nunca são alcançados, o aplicativo parece falhar antes desse ponto?