我使用IB并取消选中“在触摸时显示选择”,但它仍会在所选的单元格上显示蓝色突出显示。这是苹果的错误还是我弄错了。
答案 0 :(得分:19)
这可能是IB中的一个错误,正如您在文档中看到的那样,表视图没有任何触摸显示选项的属性。它是tableview cell的属性。所以复选框不应出现在IB中。可能你可以用苹果提交一个错误,看看他们对此有什么看法。
为了获得效果,你应该这样做:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
}
希望这有帮助。
答案 1 :(得分:0)
我也觉得它很可能是一个错误。但是,基于以下观察,我只是偶然发现了一个完美的解决方法。
highlighted
on touch down and selected
on touch up。-setHighlighted:animated:
和-setSelected:animated:
根据其选择样式突出显示单元格,即,将其中任何一个打开而另一个处于关闭时突出显示单元格。highlighted
关闭(通常情况下,下面的解决方案只需要进行适当的调整,根据您的具体情况很容易找出。)鉴于上述情况,只需将UITableViewCell子类化并覆盖setHighlighted:animated:
,而无需调用super
的实现。因此,所有转向highlighted
的努力都将被抑制,并且突出显示仅在触摸时发生,而不是在触地时发生,这正是在关闭“触摸显示选择”时所期望的。
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
// hack to get the effect of unchecking "Show Selection on Touch" option of UITableView in IB which has no effect
}
在修补时,单元格为selected
,但不是animated
。如果你想要动画,我发现调用如下所示的委托方法可以为选择设置动画。
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_itemsTable selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
return indexPath;
}