我有一个 .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/