2011-02-18 60 views
1

當我點擊我的表格視圖單元格時,其背景顏色不會變爲藍色。有什麼理由呢?TableViewCell顏色在點擊時不會改變

在點擊一個單元格時,我在單元格的正確視圖上打上覆選標記,如果點擊具有複選標記的同一單元格,單元格會發出藍色背景色,但不包含不包含該單元格的單元格複選標記。

我試圖

[iTableView cellForRowAtIndexPath:iIndexPath].selectionStyle = UITableViewCellSelectionStyleBlue; 

在我

- (void)tableView:(UITableView *)iTableView didSelectRowAtIndexPath:(NSIndexPath *)iIndexPath { 

,但它並沒有幫助。

+0

我注意到你一直在使用可可標籤廣泛用於iOS相關的問題。只是你知道,相應的iOS標籤是可可觸摸的。 – 2011-02-18 23:48:09

回答

2

嘗試設置單元格的selectionStyletableView:cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Cell setup 

    cell.selectionStyle = UITableViewCellSelectionStyleBlue; // or Gray/None 

    return cell; 
} 
2

或者你也可以通過這種方式

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 

     UITableViewCell* cell = [tableView cellForRowAtIndexPath:indexPath]; 
     cell.textLabel.shadowColor = [UIColor redColor]; 
     [cell.contentView setBackgroundColor:[UIColor greenColor]]; 
     [cell setBackgroundColor:[UIColor magentaColor]]; 

    } 

您可以更改爲textLabel,細胞,細胞的內容視圖的顏色做到這一點。 希望這也能幫助你。