2017-09-15 66 views
-2

我遇到了我的UITableView定製單元格問題。iOS桌面視圖定製單元格出現問題

這是UITableView的代碼:

var contactName = ["Papa", "Mummy", "Ajay", "Deepak", "My"] 
var phoneNumber = ["657464567", "354636346", "5436346", "6345634643", "5645634656"] 

// MARK: - Table view data source 
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return contactName.count 
} 

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! myTableViewCell 
    cell.name.text = contactName[indexPath.row] 
    return cell 
} 

這是我的自定義單元代碼:

@IBOutlet weak var name: UILabel! 

我仔細檢查了,一切都已經正確連接,請幫我找出爲什麼我有這個問題。

+0

您是否收到任何錯誤?如果是的話,你可以發佈該錯誤 –

+0

錯誤不顯示只是它顯示設備或模擬器中的空表 –

+0

您是否設置了tableview的數據源? –

回答

0

已使用的UITableViewController,所以你需要返回段的數量爲1。所以,改變像下面的代碼:

override func numberOfSections(in tableView: UITableView) -> Int { 
     return 0 
    } 

override func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 
+0

我已經刪除了該功能,所以它的默認值是1,而且我一直這樣寫這樣的方式,我也試過這是(上面提到的一個)我不是這裏的問題 –

+0

然後你有沒有碰到在日誌中。請張貼 – Vinodh