![](/img/trans.png)
[英]Must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
[英]Prototype Cells in a nib instead of a storyboard
為了更好的可重用性,我想在Storyboard之外創建一個表視圖。
現在,當我在Xcode中使用Nib創建基於UITableView
的ViewController時,我在nib文件中獲得了默認的TableView。 但是,我無法在Interface Builder中添加原型單元格,就像我在Storyboard中一樣。
目前是不是可以在筆尖中添加原型單元格,或者我錯過了什么。
非常感謝您的幫助。
iOS 5在UITableView上包含一個新方法: registerNib:forCellReuseIdentifier:
要使用它,請在筆尖中放置UITableViewCell。 它必須是筆尖中唯一的根對象。
您可以在加載tableView后注冊nib,然后在調用dequeueReusableCellWithIdentifier時:使用單元標識符,它將從nib中拉出它,就像使用了Storyboard原型單元一樣。
在Swift 4中:
重要 - 在viewDidLoad中注冊 nib文件
yourTableview.register(UINib.init(nibName: "CustomCellTableViewCell", bundle: nil), forCellReuseIdentifier: "Cell")
(要么)
yourTableview.register(UINib(nibName: "CustomCellTableViewCell", bundle: Bundle.main), forCellReuseIdentifier: "Cell")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.