2010-01-27 73 views

回答

19

这可能是IB中的一个错误,正如您在文档中看到的那样,表格视图没有任何属性可用于触摸显示选择。它是tableview单元格的属性。所以复选框不应该出现在IB中。可能你可以用苹果提交一个bug,看看他们对它的评价。

为了得到效果,你应该这样做,如:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 

      cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
      if (cell == nil) { 
       cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2]; 
       [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; 
      } 
    } 

希望这有助于。

0

我也觉得这很可能是一个错误。但是,我只是基于以下观察找到了一个完美的解决方法。

  • The cell is 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; 
}