2011-04-18 50 views
5

嘿,我得到一个非常奇怪的错误,我无法弄清楚如何解决它:当我在UITableView中滚动时,它有时会突出显示蓝色的单元格,即使当我没有完全选择。UITableViewCell在滚动时变成蓝色

例如:
- 细胞1-
- 细胞2-
- 细胞3-
- 细胞4-
如果我把手指向下在小区2和滚动到小区4会留下单元格2突出显示,即使didSelectRowAtIndexPath:从不被触发。

任何想法?

编辑 添加代码:

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; 
+0

你能告诉我们cellForRowAtIndexPath中的单元格创建代码吗? – 2011-04-18 06:39:03

+0

请告诉我们你在'CellForRowAtIndexPath'委托中做了什么? – 2011-04-18 06:45:49

回答

0

您可以使用在创建细胞以下。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

cell = Your allocation. 

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

我想你也需要请有看看UIViewTable物业触摸即延迟内容风格和撤销内容润色。

希望这会有所帮助。

+0

当我滚动时,这会摆脱选择,但不幸的是,如果用户实际选择了行,它不会变成蓝色。 – Rob 2011-04-18 09:16:16

0

在您的UITableView委托中覆盖-tableView:willSelectRowAtIndexPath:并返回nil,以确保您不允许它选择行。

+0

我想他希望细胞可以选择。他的观点是当你滚动视图时。 – 2011-04-18 07:06:04

+0

这不允许我选择行 – Rob 2011-04-18 09:16:34

1

固定它!

我的解决办法是两个部分组成:

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 animated:YES];”到didSelectRowAtIndexPath:而不是我曾经有“[[tableView cellForRowAtIndexPath:indexPath] setSelected:NO];”这在很多层面上都是错误的。

[tableView deselectRowAtIndexPath:indexPath animated:YES]; 

希望能帮助有这个问题的人。案件结案。

相关问题