2012-07-20 24 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]; 
} 
相關問題