2010-07-23 32 views
1

當我的用戶點擊一個細胞我希望文字變成白色製作的UITableViewCell文白:問題時選擇

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 

    [super setSelected:selected animated:animated]; 
    lblName.textColor = [UIColor whiteColor]; 
    lblTime.textColor = [UIColor whiteColor]; 
} 

這工作得很好,但是當用戶選擇另一個單元格,前一小區的文本顏色遺體白色。我怎樣才能將它恢復爲黑色?

+2

我想代碼只是爲了展示你想達到的目的?如果不是,爲什麼不使用「選定」變量來決定要將哪種顏色分配給標籤? – Benjamin 2010-07-23 18:12:22

+0

DOH。感謝您指出明顯。我應該看到這一點。 – 2010-07-23 18:18:05

回答

2
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSIndexPath *oldIndexPath; 

    UITableViewCell *cell1 = [tableView cellForRowAtIndexPath:indexPath]; 
    UITableViewCell *cell2 = [tableView cellForRowAtIndexPath:oldIndexPath]; 
    cell1.textLabel.textColor = [UIColor whiteColor]; 
    cell2.textLabel.textColor = [UIColor blackColor]; 

    oldIndexPath = indexPath; 
}