【发布时间】:2023-03-27 17:31:01
【问题描述】:
目前我正在使用UITableViewSelectionStyleNone 覆盖标准 UITableViewSelectionStyle,然后根据委托方法更改单元格的颜色:
- (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”
【问题讨论】:
-
indexPath
2147483647等价于NSNotFound。
标签: ios objective-c uitableview