2018-07-17 cellForRowAtIndexPath不执行的原因

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。