我已经搜索了几个小时,发现了许多提示,但没有找到解决方案。我有一个非常简单的静态单元格tableview。我正在关注Apple文档。我没有使用storyboard,我没有选择自动布局,将文档版本设置为iOS5。它在iOS6中工作得很好,但iOS5中的单元格为NIL,因此它会崩溃。静态表格视图适用于iOS6,但不适用于iOS5
细胞在IB中完成,我有属性连线,我有细胞标识符(实际上不需要,但没有区别)。日志语句在iOS5中返回(null),但在iOS6中正确返回一个单元格。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
if (indexPath.row ==0) {
cell0.selectionStyle = UITableViewCellSelectionStyleNone;
NSLog(@"description = %@",[cell0 description]);
return cell0;
}
if (indexPath.row ==1) {
cell1.selectionStyle = UITableViewCellSelectionStyleNone;
return cell1;
}
if (indexPath.row ==2) {
cell2.selectionStyle = UITableViewCellSelectionStyleNone;
return cell2;
}
if (indexPath.row ==3) {
cell3.selectionStyle = UITableViewCellSelectionStyleNone;
return cell3;
}
}
cell4.selectionStyle = UITableViewCellSelectionStyleNone;
return cell4;
}
在此先感谢您指点我正确的方向。我知道这一定很简单,但它让我发疯。
Martin,感谢您的回复。不幸的是,我得到完全相同的错误消息,NSLOG为单元格的描述返回null。 – user2373373 2013-05-12 16:06:25
UITableViewCell * cell1 = [tableview dequeueReusableCellWithIdentifier:@“cell1”];将此方法替换为UITableViewCell * cell1 = [tableview dequeueReusableCellWithIdentifier:@“cell1”forIndexPath:indexpath.row];或者UITableViewCell * cell1 = [tableview dequeueReusableCellWithIdentifier:@“cell1”forIndex:index]; //我不知道确切的方法。尝试ATLEAST这一个 – MARTIN 2013-05-12 16:16:34
我知道这种方法的iOS5和6之间改变不过,我不应该需要任何可重复使用的细胞在静态视图没有什么可以重复使用(所有自定义细胞是不同的) – user2373373 2013-05-12 16:27:31