ios - 单个 Storyboard swift 中的多个 TableView

标签 ios iphone uitableview swift

我试图在一个 View Controller 中有 2 个 TableView ,其中一个 TableView 是静态的,而 另一个动态。

我的 View Controller 是这样设置的 enter image description here

上半部分是静态表格 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”标识符

enter image description here

关于ios - 单个 Storyboard swift 中的多个 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26537847/

相关文章:

iphone - 如何更改自动生成的导航栏 Xcode

ios - 拖动单元格时如何在 UITableViewCell 中隐藏阴影

ios - 滚动后重复相同的单元格

ios - Xcode 5 & OSX Mavericks 为 iOS6.1 编译不工作

ios - 我如何应用 CICrystallize 过滤器 iOS 7?

ios - 具有多个对象的 NSArray

ios - 检查字符串是否包含 Swift 中的特殊字符

iphone - 从 self.view 中删除所有 subview 的最佳方法是什么?

ios - 如何使用蓝牙 LE iOS 在桌面 View 上显示找到的设备列表

ios - UITapGestureRecognizer 不适用于 UITextField 的自定义子类