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

Iphone 更新UIViewTableCell';单击附件URL时的背景,iphone,cocoa-touch,uitableview,Iphone,Cocoa Touch,Uitableview,在tableView:accessorybuttonappedforrowwithindexath:选择器中,我想更新单元格的backgroundColor 我可以使用cellforrowatinexpath:获取UIViewTableCell,但我不确定如何更新其背景色。代码beliw似乎不起作用 [_tableView beginUpdates]; cell.backgroundColor = [UIColor grayColor]; [_tableView endU

tableView:accessorybuttonappedforrowwithindexath:
选择器中,我想更新单元格的
backgroundColor

我可以使用
cellforrowatinexpath:
获取
UIViewTableCell
,但我不确定如何更新其背景色。代码beliw似乎不起作用

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

有什么建议吗?

我会先试试
[cell setNeedsDisplay]

另外,
beginUpdates
endUpdates
用于插入/删除行等。因此我认为这里没有必要

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

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
表视图在使用单元格绘制行之前将此消息发送给其委托,从而允许委托在显示单元格对象之前对其进行自定义。此方法使代理有机会覆盖先前由表视图设置的基于状态的属性,例如选择和背景色。代理返回后,表视图仅设置alpha和frame属性,然后仅设置行滑入或滑出时的动画


tableView:willDisplayCell:ForRowatineXpath:仅在首次加载表时调用。如果我想在单击accesoryURL时更改它,则设置[tableView setNeedsLayout]不会导致调用此方法。你知道我怎样才能做到吗?