cellForRowAtIndexPath不执行的原因
表层原因:
1.dataSource和delegate没有设置
2.numberOfRowsInSection和numberOfRowsInSection返回的数据不是大于�0的整数
3.tableView没有添加到父视图上(这种情况,第2点种的方法都执行了)
(链接:https://www.jianshu.com/p/88a735f0152e)
其他原因:
1.如果是多个控制器嵌套布局,可能会出现的问题:
本来的tableview是通过懒加载创建的的,然后 [self.view addSubview:self.tableview] 添加到视图上;
- (UITableView *)tableView
{
if (_tableView == nil) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
}
return _tableView;
}
解决方法: 创建视图的时候就添加
- (UITableView *)tableView
{
if (_tableView == nil) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
[self.view addSubview:_tableView];
}
return _tableView;
}
遇到同样的问题,部分转自:https://blog.csdn.net/jeffasd/article/details/50331771
另参考问题:https://www.cnblogs.com/cl7429/p/5168569.html
网友评论