2013-04-17 21 views
0

我有一個UITableView當它在編輯模式下,選定單元格獲取其背景突出,但高亮顏色我分配到標籤上的電池沒有得到在編輯模式中應用盡管在普通模式下它的選擇效果很好。爲什麼UITableViewCell中強調色在編輯模式下不顯示

UILabel *desc = [[[UILabel alloc]initWithFrame:CGRectMake(self.textXStart, descYStart, self.descWidth, descHeight)]autorelease]; 
desc.lineBreakMode = self.descLineBreakMode; 
desc.font = font; 
desc.textAlignment = NSTextAlignmentLeft; 
desc.numberOfLines = self.descLinesNumber; 
desc.text = descText; 

desc.highlightedTextColor = [UIColor whiteColor]; 

然後我把它添加到單元格內容視圖

突出顯示的顏色被顯示,通常情況下,但是當我點擊編輯按鈕,然後選擇單元格中的標籤文本沒有突出顯示的顏色。

你認爲什麼是這個問題的原因。

+0

你能發佈更多周圍的代碼?我只是試着將該代碼粘貼到一個項目中(刪除這些位以設置字體,對齊方式和行數),並且它似乎100%正常工作。我的表格設置爲允許在編輯過程中進行單個選擇。嘗試建立一個新的項目,僅僅是最小的行爲(具有單個表的一個視圖,以及代碼中添加了hilightedTextColor標籤),看看是否可以複製的行爲。 –

回答

1

我碰到了這個相同的問題。什麼工作對我來說是覆蓋didSelectRowAtIndexPath方法和didDeselectRowAtIndexPath AMD手動設置標籤的顏色在我的自定義單元格。

另外你需要確保你打電話重裝數據,當您進入和退出編輯模式。

- (void)setEditing:(BOOL)editing animated:(BOOL)animated 
{ 
    [super setEditing:editing animated:animated]; 
    [[self tableView] reloadData]; 
} 

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { 
    DocumentCell *cell = (DocumentCell *) [tableView cellForRowAtIndexPath:indexPath]; 
    if([cell isEditing]) { 
     cell.titleLabel.textColor = [UIColor blackColor]; 
     cell.dateLabel.textColor = [UIColor blackColor]; 
     cell.tagsLabel.textColor = [UIColor blackColor]; 
    } 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    DocumentCell *cell = (DocumentCell *) [tableView cellForRowAtIndexPath:indexPath]; 
    if([cell isEditing]) { 
     cell.titleLabel.textColor = [UIColor whiteColor]; 
     cell.dateLabel.textColor = [UIColor whiteColor]; 
     cell.tagsLabel.textColor = [UIColor whiteColor]; 
    } 
} 
相關問題