unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
Have you set the Table Cell identifier to "Cell" in your storyboard?
Or have you set the class for the UITableViewController
to your class in that scene?
Swift unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
Well, i'm not sure how you configured your search controller but if you have initialized the controller with another controller, you must register programmatically your cell every time the results VC appears on the screen.
init(searchResultsController searchResultsController: UIViewController?)
That is true if searchResultsController != nil
You can register the cell in the following method:
func willPresentSearchController(_ searchController: UISearchController)
How to fix 'unable to dequeue a cell' error in Swift
If you are getting an “unable to dequeue a cell” error even though each table has registered its appropriate cell identifier, that means that you likely instantiated a cell for one table when cellFor
was called for the other. This is easy to do when you have a single set of UITableViewDataSource
methods servicing both tables. You can confirm this by adding a breakpoint in cellFor
, compare the tableView
passed to that method to your two outlets for messageTableView
and listTableView
: Ensure sure you’re instantiating a cell appropriate for that table.
Rather than having cellFor
rely upon currentTable
, I’d suggest just checking tableView
to determine which type of cell is to be instantiated. Then it’s impossible to instantiate the wrong cell at all. You can probably even eliminate currentTable
altogether.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch tableView {
case messageTableView:
...
case listTableView:
...
default:
fatalError()
}
}
Frankly, I’d discourage using a single UITableViewDataSource
for two different tables. An alternative is to encapsulate the UITableViewDataSource
for each into its own object, and it again makes it impossible to instantiate the wrong cell for the given table. It also helps mitigate view controller bloat.
Unable to dequeue a cell with identifier costumeCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
You probably need to register your cell. It would look something like this.
If you're using a cell class in code:
tableView.register(MyTableViewCell.self, forCellReuseIdentifier: "Cell")
If you're using a cell with a nib:
let nib = UINib(nibName: "MyTableViewCellNibFile", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "Cell")
If you're using a storyboard you need to make sure your prototype cell is setup properly. This answer actually has that defined well https://stackoverflow.com/a/14939860/563381
https://developer.apple.com/reference/uikit/uitableview/1614937-register
Swift - UITableView 'unable to dequeue a cell with identifier Cell'
Make sure that somewhere (probably in TableViewController
's viewDidLoad
), you register the cell class:
Swift 4:
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "Cell")
Swift 3 and below:
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
Related Topics
Save Uiimage Array in Nsuserdefaults
iPhone Simulator Plays Video, Real Device Won'T
iOS 8: Autorotation Is Not Working Without Storyboard
Exception: Cannot Manually Set the Delegate on a Uinavigationbar Managed by a Controller
Delegate Method to Uitableviewcell Swift
iOS Revoke Location Services Permission Programmatically
Can't Set Calayer's Border Color
Empty Return Value from Swift Function Containing Closure
How to Send Emails in Swift Using Mailgun
Swift: Extracting/Downcasting Cftype Based Coretext Types in a Cfarray
Longer Subtitles in Mapview Annotations (Swift)
How to Insert a Override Function into a If Else Statement
Implementing State Restoration in iOS 14
Increment Tab Bar Badge W/ Uialertaction Swift
Uitextview as Inputaccessoryview Doesn't Render Text Until After Animation
Swiftui Card Flip Animation with Two Views, One of Which Is Embedded Within a Stack