Pretty simple code:
func numberOfSectionsInTableView(tableView: UITableView?) -> Int {
return 1
}
func tableView(tableView:UITableView!, numberOfRows
In my case it was the way the Optional is unwrapped:
let cellId:String = "ConverterTableCell"
let cell: ConverterTableViewCell = (tableView.dequeueReusableCellWithIdentifier(cellId)! as? ConverterTableViewCell)!
I am getting this error whenever I use reuse Identifer name different than the custom class name unifid those names solve it for me
If you're using storyboard, make sure you don't have this line at the start of your file:
self.tableView.registerClass(CustomTableViewCell.self, forCellReuseIdentifier: "customCell")
It will overwrite the storyboard and as a result, the outlet links in the storyboard are ignored.
When you create a view in code, its IBOutlet
properties don't get hooked up properly. You want the version that you get back from dequeueReusableCellWithIdentifier
:
let cell = tableView.dequeueReusableCellWithIdentifier("BookCell") as BookTableViewCell
I encounter this error, if I put UITapGestureRecognizer in a custom UITableViewCell on the storyboard.(Xcode version is 8.3).
The reason why this question gets asked a lot is because it depends on how you setup your tableview and custom CellClass. Do you create your tableview in storyboard or programmatically? Do you create custom .xib Cells and custom Cell classes?
If you created your tableview programmatically and created custom .xib and Cell class here is the answer for Swift 4:
in viewDidLoad:
customTable.register(UINib(nibName: "NibName", bundle: nil), forCellReuseIdentifier: "NibNameIdentifier")
in cellforRowat:
let cell = tableView.dequeueReusableCell(withIdentifier: "NibName") as! ClassName
Note: In your cell .xib file make sure you set your identifier in the Attributes inspector ("NibNameIdentifier").