2011-12-18 53 views
0

得到的代码,但detailText仅在第一“列”表示的情况下,0Detailtext仅在第一个标签表示

代码是下:的cellForRowAtIndexPath

if (indexPath.row == 0) { 

     cell.detailTextLabel.text = @"A"; 
    } 

}  

else if (indexPath.row == 1){ 

cell.detailTextLabel.text = @"B"; 

} 

else if (indexPath.row == 2){ 

cell.detailTextLabel.text = @"C"; 

} 

else if (indexPath.row == 3){ 

cell.detailTextLabel.text = @"D"; 

} 

回答

1

有一个明显的右撑条不匹配,你的代码更改为:

if (indexPath.row == 0) { 
    cell.detailTextLabel.text = @"A"; 
} 
else if (indexPath.row == 1) { 
    cell.detailTextLabel.text = @"B"; 
... 

可以缩短,要

cell.detailTextLabel.text = [@"ABCD" substringWithRange:NSMakeRange(indexPath.row,1)]; 
+1

'characterAtIndex:'返回一个'unichar',而不是'NSString',所以不起作用。在这种情况下,你会使用'substringWithRange:'。 – omz 2011-12-18 20:42:03

+0

@omz好的,我已经更新了我的答案。 – 2011-12-18 20:49:56

相关问题