不调用自定义TableViewController tableView()方法
问题描述:
这里是我自定义的TableViewController
类。不调用自定义TableViewController tableView()方法
我插入打印语句在viewDidLoad
和tableView
方法
viewDidLoad
被打印到控制台,但tableView
不是
我确信添加标识Device Cell
的属性编辑器,所以我不肯定我做错了什么
class MyTableViewController: UITableViewController {
// ... some code
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad")
}
// ... some code
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell =
tableView.dequeueReusableCell(
withIdentifier: "Device Cell", for: indexPath)
// Configure the cell...
print("tableView")
let device = mWifiDevices[indexPath.row]
cell.textLabel?.text = device.mIpAddress
return cell
}
// ... some code
}
答
Doh!解决方案仅仅是添加行和段计数的获取者问题
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return mWifiDevices.count
}
你有任何单元吗?向我们展示一个代码,您可以在其中设置其中应该有多少人的代码 –
@Lu_您说得对,我忘了这么做! –
你重新加载UITableView?怎么样设置tableView中的项目数量? – Jay