I have a TableViewController and static cells inside it; and I am trying to give one of the cells a class and detect it with dequeueReusableCellWithIdentifier
. I use..
class MyCell: UITableViewCell {
}
But when I use this it crashes
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let cell = tableView.dequeueReusableCellWithIdentifier("MyCell", forIndexPath: indexPath) as! MyCell
}
unable to dequeue a cell with identifier MyCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
The problem is that you are trying to deque cell in
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
}
Never deque cells outside of tableView:cellForRowAtIndexPath:
If you want an instance of the cell, you can just use
tableView.cellForRowAtIndexPath(indexPath)
This'll solve the problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.