2017-10-17 159 views
0

這裏是我自定義的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

回答

0

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 
}