senty
senty

Reputation: 12847

`Unable to dequeue a cell with identifier MyCell`

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 {

}

enter image description here

enter image description here

enter image description here

enter image description here

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'

Upvotes: 1

Views: 284

Answers (1)

Varun
Varun

Reputation: 759

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.

Upvotes: 2

Related Questions