繁体   English   中英

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

[英]Custom TableViewController tableView() method not called

这是我的自定义TableViewController类。

我在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  
}

h! 解决方案仅是添加行数和节数获取器的问题

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
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM