2014-04-29 57 views
1

問題是tableview中單元格的內容不顯示!!碼的TableView註冊類:forCellReuseIdentifier不起作用

列表部分

1.在視圖控制器

@property (strong, nonatomic) IBOutlet UITableView *mtableview; 

2.在viewDidLoad中

self.mtableview.delegate = self; 

self.mtableview.dataSource = self; 

[self.mtableview registerClass:[MyTableViewCell 
class]forCellReuseIdentifier:@"MytableViewcell" ]; 

3.在tableview中的cellForRowAtIndexPath:

MyTableViewCell *mcell = [tableView 
    dequeueReusableCellWithIdentifier:@"MytableViewcell" forIndexPath:indexPath]; 

    mcell.mdataname.text = [mdataArray objectAtIndex:indexPath.row]; 

4.在MyTableViewCell

@property (strong, nonatomic) IBOutlet UILabel *mdataname; 

5.我發現MCELL不爲零,就已經頁頭,但mcell.mdataname是零

6.如果我使用故事板設置MyTableViewCell標識符,並刪除

[self.mtableview registerClass:[MyTableViewCell 
    class]forCellReuseIdentifier:@"MytableViewcell" ]; 

tableview中單元格的內容顯示!!

7.所以我們不能以編程方式設置單元格的標識符?

回答

2

看起來你應該有一個與自定義單元類關聯的XIB,並且你應該在代碼中加載關聯的NIB文件並註冊NIB(而不是註冊類)。

要麼是這樣,要麼是您的班級在initWithStyle:reuseIdentifier:方法中沒有正確配置自己(儘管此選項看起來不太可能,因爲您使用的是IBOutlet)。

目前,無論您有什麼問題,mdataname都不會從存檔創建/加載。

+0

我發現如果在我的自定義tabelviewCell(initWithStyle:reuseIdentifier:)中初始化IBoutlet組件,則會顯示內容。謝謝。你的猜測是對的。 – user3365407