0

Even though I have written the code as given below and In the storyboard , identifier has been set for SortTableViewCell, it is showing throwing an exception :

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier SortTableCellID - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

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

    let cell = tableView.dequeueReusableCell(withIdentifier: "SortTableCellID", for: indexPath) as! SortTableViewCell
    cell.sortValues.text = sortArray[indexPath.row]
    return cell
}

The code ain't working after the Xcode(Xcode 10 -> Xcode 11) updating to its latest version, it seems to show an error while running the same code.As a newbie to Swift, please somebody help me to sort this out.

varsha94
  • 249
  • 1
  • 6
  • 22

1 Answers1

1

As the crash clearly says

You need to register nib or xib before use as cell in tableview

The system is not able to identify the cell for the tableview(like which cell be used to display in tableview).

If you are not using xib

If you are not using xib then please verify the following things...

  • You've specified the Reuse Cell Identifier in storyboard.(Select cell from tableview in you have created)

enter image description here

  • You have specified a class for tableview cell.

enter image description here

When using xib

let nib = UINib(nibName: "SortTableViewCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "SortTableViewCell")
Mahendra
  • 8,448
  • 3
  • 33
  • 56