Barak Shoushan Barak Shoushan - 2 months ago 240
Swift Question

'UITableView' failed to obtain a cell from its dataSource

I updated Xcode and since then I'v problems with my dataBase.
code:

override func numberOfSections(in tableView: UITableView) -> Int {
// return the number of sections
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
// return the number of rows
return leadItems.count
}

func cellForRow(at indexPath: IndexPath) -> UITableViewCell?
{
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! LeadsTableViewCell

// Configure the cell...
cell.user_name_label.text = leadItems[indexPath.row].user_name
cell.school_name_label.text = leadItems[indexPath.row].school_name

return cell
}


The error that I get is:


Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView (; layer = ; contentOffset: {0, -64}; contentSize: {375, 65802}>) failed to obtain a cell from its dataSource ()

Answer

Your method name for cellForRow is not correct.

Replace this line

func cellForRow(at indexPath: IndexPath) -> UITableViewCell?
{

with

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {