let cell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MessageTableViewCell
let cell2 = tableView!.dequeueReusableCellWithIdentifier("Cell2", forIndexPath: indexPath) as MessageTableViewCell
第一个单元格被认为是正确的。第二,不是。我有一个故事板,为每个原型单元设置了正确的标识符。(动态)tableView上有两个单元格,据我所知应该没问题。这是我收到的确切错误:
*由于未捕获的异常“ NSInternalInconsistencyException”而终止应用程序,原因:“无法使标识符为Cell2的单元出队-必须为该标识符注册一个笔尖或一个类,或者在情节提要中连接原型单元
如果该第二个原型单元的标识符不是“ Cell2”,那将是非常合理的。
这是整个函数中的代码,请注意我什至不返回单元格2,只是使它出队:
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {
let cell = tableView!.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as MessageTableViewCell
let cell2 = tableView!.dequeueReusableCellWithIdentifier("Cell2", forIndexPath: indexPath) as MessageTableViewCell
if UIApplication.sharedApplication().statusBarOrientation.isLandscape == true {
cell.messageLabel.preferredMaxLayoutWidth = cell.frame.size.width - 80
} else {
cell.messageLabel.preferredMaxLayoutWidth = cell.frame.size.width - 35
}
preferredWidth = cell.messageLabel.preferredMaxLayoutWidth
cell.messageLabel.text = friends[indexPath!.row]
cell.messageLabel.sizeToFit()
cell.messageLabel.setNeedsDisplay()
return cell
}
它在第二行(函数内部)崩溃。
注意:我现在正在使用XCode 6 Beta 4。
我创建了一个新笔尖,在其中重新创建了单元格,并插入了此代码,所有这些结合起来解决了问题。
var nibName = UINib(nibName: "MainTableViewCell", bundle:nil)
self.tableView.registerNib(nibName, forCellReuseIdentifier: "SecondCell")
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句