不调用自定义TableViewController tableView()方法

问题描述:

这里是我自定义的TableViewController类。不调用自定义TableViewController tableView()方法

我插入打印语句在viewDidLoadtableView方法

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 
} 
+0

你有任何单元吗?向我们展示一个代码,您可以在其中设置其中应该有多少人的代码 –

+0

@Lu_您说得对,我忘了这么做! –

+0

你重新加载UITableView?怎么样设置tableView中的项目数量? – Jay

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 
}