滚动时UITableViewCell变为蓝色

问题描述

| 大家好,我遇到了一个非常奇怪的错误,我无法弄清楚如何解决它:当我在UITableView中滚动时,即使我未完全选择它,有时也会突出显示一个蓝色的单元格。 例如: -单元格1- -单元格2- -单元格3- -单元格4- 如果我将手指放在单元格2上并滚动到单元格4,即使didSelectRowAtIndexPath:从未触发过,它也会使单元格2高亮显示。 有任何想法吗? 编辑 添加的代码:
UITableViewCell *cell = nil;

    static NSString *cellId = @\"StyleDefault\";
    cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] 
                 initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease];
    }

    cell.textLabel.text = @\"Cell One\";
    cell.textLabel.textAlignment = UITextAlignmentCenter;
    [cell setAccessoryView:nil];

    return cell;
    

解决方法

固定它! 我的解决方案包括两个部分: 1)在cellForRowAtIndexPath中:放置\“ cell.selected = NO; \”,这可以解决以下问题:如果该单元格被触碰到了,然后退出屏幕(滚动)。
UITableViewCell *cell = nil;

static NSString *cellId = @\"StyleDefault\";
cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] 
             initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease];
}

cell.textLabel.text = @\"Cell One\";
cell.textLabel.textAlignment = UITextAlignmentCenter;
[cell setAccessoryView:nil];

//Here:
cell.selected = NO;

return cell;
2)将\“ [tableView deselectRowAtIndexPath:indexPath animation:YES]; \”放到didSelectRowAtIndexPath:中,而不是以前使用的“ [[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO]; \” 。
[tableView deselectRowAtIndexPath:indexPath animated:YES];
希望对其他有此问题的人有所帮助。案件结案。     ,您可以在创建单元格时使用关注。
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell = Your allocation.

cell.selectionStyle = UITableViewCellSelectionStyleNone;
我想您还需要查看Touch的UIViewTable属性,即延迟内容触摸和可取消的内容触摸。 希望这可以帮助。     ,在您的UITableView委托中重写-tableView:willSelectRowAtIndexPath:,并为所有内容返回nil,以确保您不允许它选择行。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...