TableView registerClass:forCellReuseIdentifier不起作用

问题是tableview中单元格的内容不显示!

列出代码的一部分

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; 

我发现mcell不是零,它已经被分配,但是mcell.mdataname是零

6.如果我使用storyboard来设置MyTableViewCell标识符,并删除

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

tableview中的单元格的内容显示!

7.所以我们不能以编程方式设置单元格的标识符?

它看起来应该有一个与自定义单元类关联的XIB,并且您应该在代码中加载关联的NIB文件并注册NIB(而不是注册该类)。

要么是这样,要么是你的类没有在initWithStyle:reuseIdentifier:方法中正确configuration自己(尽pipe这个选项看起来不像你使用的是IBOutlet )。

目前,无论你有mdataname问题, mdataname是从存档中创build/加载的。