2014-08-29 207 views
0

我想更改點擊時表格單元格的顏色。當輕拍被釋放時,它會達到其初始顏色。我沒有應用選擇風格。我試圖在選擇方法中改變顏色,但是在敲擊之後它會改變顏色,並且效果是永久性的。Ios中的表格單元格顏色

回答

1
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 
    [self setCellColor:[UIColor yellowColor] ForCell:cell]; 
} 
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 
    [self setCellColor:[UIColor colorWithWhite:1.0 alpha:1.0] ForCell:cell]; 
} 
- (void)setCellColor:(UIColor *)color ForCell:(UITableViewCell *)cell { 
    cell.contentView.backgroundColor = color; 
    cell.backgroundColor = color; 
}