目前,我正在使用 UITableViewSelectionStyleNone
覆盖标准 UITableViewSelectionStyle,然后根据委托(delegate)方法更改单元格的颜色:
- (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] 它工作得很好。这是为什么……
编辑:
不知何故,当我在 didUnhlightRowAtIndexPath 之后打印出 indexPath.row 时,我从我的 NSLog 中得到“indexpath: 2147483647”
最佳答案
你可以试试:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
如果您只想在选择单元格后突出显示消失。除非我误解了你的问题。
关于ios - 删除 UITableViewCell 选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17904605/