我试图在一个 View Controller 中有 2 个 TableView ,其中一个 TableView 是静态的,而 另一个动态。
我的 View Controller 是这样设置的
上半部分是静态表格 View 。
我为两个 tableView 创建了 ibOutlets,但我似乎无法自定义表格。
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as UITableViewCell
//tableview2 is the dynamic tableView.
if (tableView == self.tableView2){
print("Tableview2")
}
else{
println("HELLLO")
}
return cell
}
我得到错误 * Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:],/SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:6116 2014-10-23 22:31:52.246 Recipe app[2857:504809] * 由于未捕获的异常 'NSInternalInconsistencyException' 而终止应用程序,原因:'无法使具有标识符 cell2 的单元格出列 - 必须注册 Nib 或标识符的类或连接 Storyboard中的原型(prototype)单元格”。
最佳答案
正如错误所说,您“必须为标识符注册一个 nib 或一个类,或者在 Storyboard中连接一个原型(prototype)单元”。
在 viewDidLoad 或 awakeFromNib 上执行此操作。
self.tableView.registerClass(UITableViewCell.classForCoder(), forCellReuseIdentifier:"cell2")
或者你必须在 Storyboard中制作原型(prototype)单元并给它“cell2”标识符
关于ios - 单个 Storyboard swift 中的多个 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26537847/