【问题标题】:Custom TableViewController tableView() method not called未调用自定义 TableViewController tableView() 方法
【发布时间】:2017-10-17 20:53:14
【问题描述】:

这是我的自定义 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  
}

【问题讨论】:

  • 你有细胞吗?向我们展示一个代码,您可以在其中设置其中应该有多少个
  • @Lu_ 你说得对,我忘了!
  • 你在重新加载 UITableView 吗?设置tableView的item个数呢?
  • 是的,这就是解决方案,谢谢!

标签: ios swift xcode xcode9


【解决方案1】:

哇!解决方案只是添加行数和节数获取器

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
}

【讨论】:

    猜你喜欢
    • 2021-12-28
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    • 2021-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多