- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath不执行的问题

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath不执行基本上只有3个原因

1. delegate没设,一定要有self.tableView.delegate = self

2. section,row的个数返回为0,或者有冲突

3. tableView的frame有问题,比如位(0,0,0,0)

我遇到的问题比较奇葩,因为我喜欢在代码里添加约束,所以都是先

initWithFrame:CGRectZero,然后添加约束。这样初始化tableView的时候它的frame为(0,0,0,0),所以不执行cellForRowAtIndexPath。

后来想了一些方法,总是有问题,后来发现:

添加的约束在viewDidLoad和viewWillAppear里都没有生效,只有在viewDidAppear里才生效,可能这就是代码添加约束的弊端。

原文地址:https://www.cnblogs.com/stevenfukua/p/4650395.html