2012-04-17 40 views
0

我有一個表格視圖,與自定義單元格,我已設置單元格上有一個突出顯示顏色的文本時,你點擊它。自定義tableview和highlightTextColor

//具體

NSString *ligneTableau = [NSString stringWithFormat:@"%@", [[table objectAtIndex:indexPath.row] nome]]; 
cell.label.text = ligneTableau; 
cell.label.font = [UIFont fontWithName:@"populaire" size:35]; 
cell.label.textColor = [UIColor colorWithRed:124.0f/255.0f green:153.0f/255.0f blue:106.0f/255.0f alpha:1.0f]; 
cell.fondo.image = [UIImage imageNamed: @"cell_ant.png"];  

//highlighted Text 

cell.label.highlightedTextColor = [UIColor colorWithRed:55.0f/255.0f green:70.0f/255.0f blue:48.0f/255.0f alpha:1.0f]; 

每一個東西做工精細,但回來到文本住宿突出表時電池。

我忘記了一些事情?

回答

0

當您返回表格時,單元格可能仍然處於選中狀態。所以一旦回到桌面,你應該取消選擇。

[cell setSelected:NO]; 
+0

感謝您的答覆,但如果我把這個 - (無效)viewDidUnload 正常工作... – Acunamatata 2012-04-17 07:41:00

+0

試在 - (void)viewDidDisappear:(BOOL)animated – mhunturk 2012-04-17 07:44:52

+0

nope,bur認爲問題是另一個,這裏是我聲明並設置我的自定義單元格。 - (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath { //豐多tabella TRASPARENTE tableView.backgroundColor = [的UIColor clearColor]; static NSString * CellIdentifier = @「Cell」; UpdatesTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];如果(cell == nil){ NSArray * topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@「UpdatesTableViewCell」owner:self options:nil]; – Acunamatata 2012-04-17 07:57:00

0

在你UpdatesTableViewCell類,可以實現以下方法:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 
    [super setHighlighted:highlighted animated:animated]; 

    if (highlighted) 
     self.label.textColor = [UIColor colorWithRed:55.0f/255.0f green:70.0f/255.0f blue:48.0f/255.0f alpha:1.0f]; 
    else 
     self.label.textColor = [UIColor colorWithRed:124.0f/255.0f green:153.0f/255.0f blue:106.0f/255.0f alpha:1.0f]; 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:selected animated:animated]; 

    if (selected) 
     self.label.textColor = [UIColor colorWithRed:55.0f/255.0f green:70.0f/255.0f blue:48.0f/255.0f alpha:1.0f]; 
    else 
     self.label.textColor = [UIColor colorWithRed:124.0f/255.0f green:153.0f/255.0f blue:106.0f/255.0f alpha:1.0f]; 
} 
+0

這是一個好主意,但有一個問題,updatesTableviewcell是一個類使用更多的一個控制器,每一個馴服改變標籤的顏色。 – Acunamatata 2012-04-17 14:44:57

+0

您正在爲每個可重用單元創建該類的新實例,如果您在多個視圖控制器中使用它,則無關緊要。你有沒有嘗試過上面的代碼?如果你希望它只發生在某些視圖控制器上,那麼你可以在'UpdatesTableViewCell'中添加另一個變量,比如'whichViewController',並且在填充表格時放置'cell.whichViewController = @「First」'。然後在你的'UpdatesTableViewCell'類中檢查上面顯示的方法中的[cell.whichViewController isEqualToString:@「First」]'。 – sooper 2012-04-17 15:02:01

+0

mmmm有趣,我不是很確定,我明白(我很新手),讓我試試! – Acunamatata 2012-04-17 15:18:48