В настоящее время я переопределяю стандартный UITableViewSelectionStyle, используя UITableViewSelectionStyleNone
, а затем меняя цвет ячейки на основе методов делегата:
- (void)tableView:(UITableView *)tableView
didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:[UIColor yellowColor]];
}
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:[UIColor whiteColor]];
}
- (void)tableView:(UITableView *)tableView
didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"indexpath: %i",indexPath.row);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:[UIColor whiteColor]];
}
- (void)tableView:(UITableView *)tableView
didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setBackgroundColor:[UIColor whiteColor]];
}
Это почти работает, за исключением того, что всякий раз, когда я выделяю ячейку, а затем оттаскиваю палец от нее, не выбирая ее, цвет не меняется на белый... если я устанавливаю его в [UIColor RedColor], он работает с совершенством. Почему это...
Edit:
Как-то, когда я распечатываю indexPath.row после didUnhlightRowAtIndexPath, я получаю "indexpath: 2147483647" из моего NSLog