2013-01-17 35 views
1

我需要爲插入的單元格設置不同的樣式,與重載的單元格相比。如何判斷單元格是否在cellForRowAtIndexPath中插入或重新加載?

我將像下面的我的細胞:

[tempArray addObject:[NSIndexPath indexPathForRow:0 inSection:0]]; 
[[self tableView] beginUpdates]; 
[[self tableView] insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop]; 
[[self tableView] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationNone]; 
[[self tableView] endUpdates]; 

有沒有爲我做了以下的方式:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (cell was inserted) { 
     cell.mylabel.textColor = [UIColor redColor]; 
    } else { 
     cell.mylabel.textColor = [UIColor blackColor]; 
    } 

} 
+0

您可以使用電池的標籤值了點。默認值爲0,將其更改爲1或其他值。 –

+0

嗯,但兩者都會使用相同的單元格類別,所以不要以爲我可以通過標記值區分它們,因爲它們會相同。 – teggy

回答

2

由於通常用於維持表的狀態的情況下查看單元格,正確答案是保持模型中的狀態。換句話說,如果tempArray是包含描述表格內容的對象集合的模型,請將BOOL屬性添加到這些對象,類似於userAdded

那麼你的「細胞插入」僞代碼可以成爲:

MyModelClass *modelElement = [tempArray objectAtIndex:indexPath.row]; 

if (modelElement.userAdded) { 
    cell.mylabel.textColor = [UIColor redColor]; 
} else { 
    cell.mylabel.textColor = [UIColor blackColor]; 
} 
+0

+1用於提示模型類的概念。 – iDev

相關問題