我有一个.xib文件,我希望它是一个表视图控制器,但是当我在.xib文件中创建一个表视图控制器时,我得到了错误Table views with embedded sections and cells are only supported in storyboard documents.我该如何解决.下面是我的实际表视图的代码.
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
}
Run Code Online (Sandbox Code Playgroud)
Xib有点过时了,当它们被发明时,没有原型单元可以在UI构建器中制作.当故事板被引入时,这个功能也是如此,除了没有后端移植到xib编辑器,所以你不能在xib中使用原型单元,不幸的是,你需要为单元格布局制作单独的xib.