代码之家  ›  专栏  ›  技术社区  ›  psychotik

单击附件URL时更新UIViewTableCell的背景

  •  0
  • psychotik  · 技术社区  · 15 年前

    tableView:accessoryButtonTappedForRowWithIndexPath: 选择器,我要更新 backgroundColor

    UIViewTableCell 使用 cellForRowAtIndexPath: 但我不知道如何更新它的背景色。密码beliw似乎不起作用。

        [_tableView beginUpdates];
        cell.backgroundColor = [UIColor grayColor];
        [_tableView endUpdates];
    

    有什么建议吗?

    1 回复  |  直到 15 年前
        1
  •  0
  •   Mike Weller    15 年前

    我先试试 [cell setNeedsDisplay];

    阿尔索 beginUpdates endUpdates

    单元格上的背景色是一件棘手的事情,因为表视图会在幕后处理单元格选择。要获得可靠的行为,需要在此UITableViewDelegate方法中设置单元格的背景色:

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
    forRowAtIndexPath:(NSIndexPath *)indexPath