Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios TableView注册表类:forCellReuseIdentifier不工作_Ios_Uitableview - Fatal编程技术网

Ios TableView注册表类:forCellReuseIdentifier不工作

Ios TableView注册表类:forCellReuseIdentifier不工作,ios,uitableview,Ios,Uitableview,问题是tableview中单元格的内容不显示 列出部分代码 1。在视图控制器中 @property (strong, nonatomic) IBOutlet UITableView *mtableview; 2。在viewDidLoad中 self.mtableview.delegate = self; self.mtableview.dataSource = self; [self.mtableview registerClass:[MyTableViewCell class]fo

问题是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;
5。我发现mcell不是nil,它是alloc,但是mcell.mdataname是nil

 @property (strong, nonatomic) IBOutlet UILabel *mdataname;
6。如果我使用故事板设置MyTableViewCell标识符,并删除

 [self.mtableview registerClass:[MyTableViewCell  
    class]forCellReuseIdentifier:@"MytableViewcell" ]; 
tableview中单元格的内容已显示


7。因此,我们无法以编程方式设置单元格的标识符?

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

或者,您的类没有在
initWithStyle:reuseIdentifier:
方法中正确配置自身(尽管在使用
IBOutlet
时,此选项的可能性较小)


目前,无论您遇到哪一个问题,
mdataname
都不是从存档中创建/加载的。

我发现,如果在我的自定义选项卡elviewcell(在initWithStyle:reuseIdentifier:)中初始化IBoutlet组件,就会显示内容。感谢你的猜测是对的。