我想將我的表格視圖中的第一個單元格的背景顏色設置爲藍色作爲例子,但它不會工作。每次我開始滾動藍色跳轉到不同的單元格。我試過這些代碼。爲單元格分配顏色不工作
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([[self.menu objectAtIndex:indexPath.row] isEqual:@"a string"]){
cell.contentView.backgroundColor=[UIColor blueColor] ;
}
}
和
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==0){
cell.contentView.backgroundColor=[UIColor blueColor] ;
}
}
和我想它也cellfro一行索引路徑。我錯過了什麼?
這是我使用的cellForRowAtIndexPath代碼:
if(indexPath.row==0){
cell.contentView.backgroundColor=[UIColor blueColor] ;
}
你錯過了第二部分。您需要一個else語句來涵蓋除if語句之外的其他情況。檢查我的帖子,看看我爲你準備的解決方案。 – Pavan 2013-04-03 22:27:37