2011-02-18 62 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,细胞,细胞的内容视图的颜色做到这一点。 希望这也能帮助你。