`无法使用标识符MyCell`

时间:2016-04-24 08:36:04

标签: ios swift uitableview delegates

我有一个TableViewController和静态单元格;我试图给其中一个单元格一个类并用dequeueReusableCellWithIdentifier检测它。我用..

class MyCell: UITableViewCell {

}

enter image description here

enter image description here

enter image description here

enter image description here

但是当我使用它时它会崩溃

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'

1 个答案:

答案 0 :(得分:2)

问题是你正试图在

中消除细胞
override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {

}

永远不要在tableView:cellForRowAtIndexPath:

之外消除细胞

如果你想要一个单元格的实例,你可以使用

tableView.cellForRowAtIndexPath(indexPath)

这将解决问题。