ios - 删除 UITableViewCell 选择

标签 ios objective-c uitableview

目前,我正在使用 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/

相关文章:

ios - 从每个 UITableViewCell 的 2 个文本字段中读取数据

ios - 创建自定义 UITableViewCell Swift 时分配 'self'

ios - NSRegularExpression 在字符后随文本颜色变化

ios - OpenGL ES IOS纹理2D颠倒绘制

ios - 使用 Parse 检索与您在同一个公会中的所有公会成员

c++ - 混合 Objective-C 和 boost/C++

ios - MPMoviePlayerLoadState DidChangeNotification 需要什么头文件?

ios - Firebase 与 FB SDK 登录冲突

iphone - UIScrollView contentSize 问题 - 带有示例代码

ios - 单击表格 View 单元格上的按钮单击单元格而不是按钮