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。
最佳答案
我也经历过。尝试这个:
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "Cell")
关于ios - XCode 6无法识别第二个tableViewCell,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25091184/