【问题标题】:TableViewCell color not changing on tappingTableViewCell 颜色在点击时不会改变
【发布时间】:2011-02-19 12:41:46
【问题描述】:

当我点击表格视图单元格时,其背景颜色不会变为蓝色。这有什么原因吗?

点击一个单元格时,我会在单元格的右视图上打一个复选标记,如果我点击具有复选标记的同一个单元格,单元格会以蓝色背景色发光,但不会在不包含复选标记的单元格上发光.

我试过了

[iTableView cellForRowAtIndexPath:iIndexPath].selectionStyle = UITableViewCellSelectionStyleBlue;

在我的

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

但它没有帮助。

【问题讨论】:

  • 我注意到您一直在广泛使用 cocoa 标签来解决与 iOS 相关的问题。顺便说一下,对应的 iOS 标签是 cocoa-touch。

标签: iphone cocoa-touch uitableview


【解决方案1】:

尝试在tableView:cellForRowAtIndexPath:中设置单元格的selectionStyle

- (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]];
    
        }
    

    您可以更改文本标签、单元格、单元格内容视图的颜色。 希望这对您也有帮助。

    【讨论】:

      猜你喜欢
      • 2019-11-06
      • 1970-01-01
      • 2015-09-25
      • 2021-04-29
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-29
      相关资源
      最近更新 更多