ios - 如何修复非法配置?

标签 ios swift

我有一个 .xib 文件,我希望它成为一个 TableView Controller ,但是当我在 .xib 文件中创建一个 TableView Controller 时,出现错误:

只有 Storyboard 文档支持带有嵌入部分和单元格的 TableView

我该如何解决这个问题?

下面是我的实际表格 View 的代码:

self.add = [Play(name: title!), Play(name: artist!), Play(name: album!)]

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.add.count
    //return count of objects in array
}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = self.tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
    var play: Play

    play = add[indexPath.row]

    cell.textLabel?.text = play.name
    return cell
}

最佳答案

Xibs 有点过时了,当它们被发明时,没有可以在 Interface Builder 中制作的原型(prototype)单元。

当引入 Storyboard 时,也提供了此功能,只是没有向后移植到 xib 编辑器,因此不幸的是,您不能在 xib 中使用原型(prototype)单元格,您需要为单元格布局制作单独的 xibs。

关于ios - 如何修复非法配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32303698/

相关文章:

ios - 是否可以在 iOS 中同时自动化两个应用程序?

ios - 从“TCHMessageType”强制转换为无关类型“String”总是失败

ios swift : UITableViewCell's tag is not updated after consecutive delete of cells

ios - canOpenURL 问题以集成最新的 Facebook sdk 4.5

iphone - NSCoding持久化UIImage

ios - xcode:添加约束后标签不显示

swift - 从 Firebase Snapshot Swift 中仅获取第一个对象

ios - admob 广告显示在按钮下但不在 viewdidload 下

ios - 单细胞还是多细胞?

ios - 有关仪器内存泄漏检测的问题