2016-07-23 50 views
2

我試圖在Swift中設置一個自定義的UITableViewCell。我也創建了XIB文件和swift文件。但是,當我運行應用程序時,單元格並未填充我的自定義單元格,而是完全空白的單元格。自定義UITableViewCell是空白(斯威夫特)

我已經註冊了我的手機有:

self.myTableView.registerClass(customCell.self, forCellReuseIdentifier: "cell") 

我也有設置如下:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return 3 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = myTableView.dequeueReusableCellWithIdentifier("cell") as! customCell 
    cell.descriptionLabel.text = "test" 
    return cell 
} 

此外,我已經安裝在自定義鏈接到一個UILabel細胞。當我嘗試更新它時,應用程序崩潰。如上所示,該行是cell.descriptionLabel.text = "test"

+1

您是否將xib的類設置爲身份檢查器下的自定義單元類? – NSGangster

+0

您是否添加了行中的部分數量? –

回答

2

而是註冊UITableViewCell類的,你必須註冊筆尖,例如:

self.tableView.registerNib(UINib(nibName: "CustomTableViewCell", bundle: nil), 
           forCellReuseIdentifier: "cell") 

nibName是廈門國際銀行文件,但沒有了.xib擴展名。

+0

工作很好!謝謝 –