Bra*_* B. 1 iphone select background uitableview
我环顾四周寻找答案,但尚未找到一个有效的答案.我想要做的就是能够更改我选择的UITableView行的背景颜色或图像.
我习惯于在选择行时转换视图,但这次我希望能够更改行的属性.我知道要使用indexPath.row更改哪一行,但我不知道如何更改行的外观,因为已经调用了cellForRowAtIndexPath方法!
我该怎么做才能改变颜色?
你会这样做:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//First you get the cell you want to change
UITableViewCell* theCell = [tableView cellForRowAtIndexPath:indexPath];
//Then you change the properties (label, text, color etc..) in your case, the background color
theCell.contentView.backgroundColor=[UIColor redColor];
//Deselect the cell so you can see the color change
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
只需确保在回收细胞时考虑这种颜色变化.
如果您需要更多信息,请发表评论.