Hiện nay tôi đang trọng các UITableViewSelectionStyle tiêu chuẩn bằng cách sử dụng UITableViewSelectionStyleNone
và sau đó thay đổi màu sắc các tế bào dựa trên phương pháp đại biểu:Loại bỏ UITableViewCell Selection
- (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]];
}
này hầu như làm việc ngoại trừ việc bất cứ khi nào tôi làm nổi bật một tế bào và sau đó kéo tôi ngón tay tắt của nó mà không thực sự lựa chọn nó, màu sắc không thay đổi sang màu trắng ... nếu tôi đặt nó thành [UIColor RedColor] nó hoạt động perfeclty. Tại sao điều này ...
Edit:
Bằng cách nào đó khi tôi in ra indexPath.row sau didUnhlightRowAtIndexPath tôi nhận được "indexPath: 2147483647" từ tôi NSLog
indexPath '2147483647' là tương đương với 'NSNotFound'. – Malloc