2012-07-20 53 views

回答

1

谢谢@Kjuly和@ Selkie的回答。我让它适用于你们两个人。

  1. set selectedBackgroundView的backgroundColor first。
  2. 变化cell.textLabel.backgroundColorcell.contentView.backgroundColordidSelectedRowAtIndexPath

再次感谢您。

+0

在我看来用户点击,选择2也不是很好的解决方法,虽然它的工作原理。因为它在选择时总是会改变单元格的正常背景颜色,而当它被取消选择时,它需要再次设置为正常! – Kjuly 2012-07-20 03:59:25

1

如何改变背景颜色的委托方法:

-(void)tableView:(UITableView *)tableView didSelectedRowAtIndexPath:(NSIndexPath *)indexPath 
2

设置selectedBackgroundView的颜色,只要你想在您的自定义的tableview细胞是什么(是的UITableViewCell的子类):

UIView * selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame]; 
[selectedBackgroundView setBackgroundColor:[UIColor redColor]]; // set color here 
[self setSelectedBackgroundView:selectedBackgroundView]; 
[selectedBackgroundView release]; 

,或者你可以在-tableView:cellForRowAtIndexPath:方法进行设置:

//... 
[cell setSelectedBackgroundView:selectedBackgroundView]; 
//... 
1

试试这个:

cell.selectionStyle = UITableViewCellSelectionStyleBlue; 
3

当所选行

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.contentView.backgroundColor = [UIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:1.0]; 
}