2011-12-18 51 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

相關問題