这个问题是由
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
函数返回值为nil引起的!!!
原始写法是这样的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ID = @"familyNumber";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
// 给cell的控件赋值
cell.textLabel.text = self.familyNumberArray[indexPath.row];
return cell;
}
可以看到,cell并没有创建。这种问题一般会发生在view中使用tableView组件时,解决办法:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ID = @"familyNumber";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if(cell == nil)
{
cell = [[UITableViewCell alloc] init];
}
// 给cell的控件赋值
cell.textLabel.text = self.familyNumberArray[indexPath.row];
return cell;
}