cellForRowAtIndexPath不執(zhí)行的原因
表層原因:
1.dataSource和delegate沒有設(shè)置
2.numberOfRowsInSection和numberOfRowsInSection返回的數(shù)據(jù)不是大于?0的整數(shù)
3.tableView沒有添加到父視圖上(這種情況,第2點(diǎn)種的方法都執(zhí)行了)
(鏈接:http://www.reibang.com/p/88a735f0152e)
其他原因:
1.如果是多個(gè)控制器嵌套布局,可能會(huì)出現(xiàn)的問題:
本來(lái)的tableview是通過懶加載創(chuàng)建的的汞斧,然后??[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;
}
解決方法: 創(chuàng)建視圖的時(shí)候就添加
- (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;
}
遇到同樣的問題除盏,部分轉(zhuǎn)自:https://blog.csdn.net/jeffasd/article/details/50331771
另參考問題:https://www.cnblogs.com/cl7429/p/5168569.html