I am getting this error when the first line of my "else" block runs:
unable to dequeue a cell with indentifier PhoneCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
So, the initial table is loading just fine, but when you try to do a search this exception is thrown. This only started happening after I went to a custom cell. Here is the cellForRowAtIndexPath function for the table that is crashing. Any idea what's going on?
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == self.tableView{
let cell = self.tableView.dequeueReusableCell(withIdentifier: "PhoneCell", for: indexPath) as! PhoneSearchResultTableViewCell
cell.nameLabel.text = phones[indexPath.row].name.value
cell.descriptionLabel.text = phones[indexPath.row].descriptionText.value
cell.modelLabel.text = phones[indexPath.row].model.value
return cell
}else{
let cell = self.resultsController.tableView.dequeueReusableCell(withIdentifier: "PhoneCell", for: indexPath) as! PhoneSearchResultTableViewCell
cell.nameLabel.text = filteredPhones[indexPath.row].name.value
cell.descriptionLabel.text = filteredPhones[indexPath.row].descriptionText.value
cell.modelLabel.text = filteredPhones[indexPath.row].model.value
return cell
}
}
Your
UITableViewControllerdoes not have either a prototype cell in it's storyboard for you"PhoneCell"or if you are doing it programmatically you did not register the class for the cell identifier you are calling.Try adding this in your
UIViewController'sviewDidLoador somewhere before you instantiate yourUITableView: