iOS桌面视图定制单元格出现问题
问题描述:
我遇到了我的UITableView
定制单元格问题。iOS桌面视图定制单元格出现问题
这是UITableView的代码:
var contactName = ["Papa", "Mummy", "Ajay", "Deepak", "My"]
var phoneNumber = ["657464567", "354636346", "5436346", "6345634643", "5645634656"]
// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return contactName.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! myTableViewCell
cell.name.text = contactName[indexPath.row]
return cell
}
这是我的自定义单元代码:
@IBOutlet weak var name: UILabel!
我仔细检查了,一切都已经正确连接,请帮我找出为什么我有这个问题。
答
已使用的UITableViewController,所以你需要返回段的数量为1。所以,改变像下面的代码:
override func numberOfSections(in tableView: UITableView) -> Int {
return 0
}
要
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
+0
我已经删除了该功能,所以它的默认值是1,而且我一直这样写这样的方式,我也试过这是(上面提到的一个)我不是这里的问题 –
+0
然后你有没有碰到在日志中。请张贴 – Vinodh
您是否收到任何错误?如果是的话,你可以发布该错误 –
错误不显示只是它显示设备或模拟器中的空表 –
您是否设置了tableview的数据源? –