问题描述
|
大家好,我遇到了一个非常奇怪的错误,我无法弄清楚如何解决它:当我在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,以确保您不允许它选择行。