【发布时间】:2016-11-02 19:51:37
【问题描述】:
我需要添加单元格标识符来为tableView 制作 ReusableCell。但是我在tableView properties 和 table view hierarchy 中没有看到任何cell。如何在表格视图中添加单元格。
注意:基本上我想创建一个Xib 文件,该文件应包含tableView,并且tableView 应具有自定义UiTableViewCell
代码在这里:
class SuggestNearTableViewCollectionViewCell: UICollectionViewCell , UITableViewDataSource,UITableViewDelegate{
@IBOutlet weak var suggestTableView : UITableView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.suggestTableView.dataSource = self
self.suggestTableView.delegate = self
suggestTableView.register(UINib(nibName: "SuggestNearTableViewCell", bundle: nil), forCellReuseIdentifier: "SuggestNearTableViewCell")
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SuggestNearTableViewCell", for: indexPath) as! SuggestNearTableViewCell
return cell
}
}
【问题讨论】:
-
为什么不赞成请评论
-
@UmairAfzal 兄弟 nib 文件有一个表格。我想要另一个 nib 文件中的称重传感器如何?
-
所以基本上你想创建一个 Xib 文件,它应该包含一个 tableView 并且 tableView 应该有自定义的 UiTableViewCell。对吗?
-
@UmairAfzal 是的兄弟