UITableview:如何禁用某些行而不是其他的选择
  我在从XML解析的组tableview内容中显示。  我想禁用它的点击事件(我不应该能够点击它)表中包含两个组。  我想禁用第一个组的选择,但不是第二个组。  点击第二组的第一行navigates到我的管player view 。 
我如何才能使特定的组或行可选?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if(indexPath.section!=0)
    if(indexPath.row==0)    
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tubeUrl]];   
}
谢谢。
  您只需将此代码放入cellForRowAtIndexPath 
  禁用单元格的选择property:点击单元格时)。 
cell.selectionStyle = UITableViewCellSelectionStyle.none
  为了能够选择(点击) cell:点击单元格)。 
// Default style
cell.selectionStyle = UITableViewCellSelectionStyle.blue
// Gray style
cell.selectionStyle = UITableViewCellSelectionStyle.gray
  请注意,具有selectionStyle = UITableViewCellSelectionStyleNone的单元格仍然会导致UI在用户触摸时调用didSelectRowAtIndexPath 。  为了避免这种情况,请按照下面的建议进行设置。 
cell.userInteractionEnabled = false
  代替。  另请注意,您可能需要设置cell.textLabel.enabled = false以灰显该项目。 
如果你想使行(或行的子集)不可选,实现UITableViewDelegate方法-tableView:willSelectRowAtIndexPath :( TechZen也提到)。 如果indexPath不能选择,则返回nil,否则返回indexPath。 要获得默认选择行为,只需返回传递给委托方法的indexPath,但也可以通过返回不同的indexPath来更改行选择。
例:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // rows in section 0 should not be selectable
    if ( indexPath.section == 0 ) return nil;
    // first 3 rows in any section should not be selectable
    if ( indexPath.row <= 2 ) return nil;
    // By default, allow row to be selected
    return indexPath;
}
从iOS 6开始,您可以使用
-tableView:shouldHighLightRowAtIndexPath:
  如果您返回NO ,则会禁用选择突出显示以及连接到该单元格的故事板触发的连线。 
  当触摸在一行上下来时调用该方法。  将NO返回到该消息会暂停选择过程,并且不会导致当前选定的行在触摸关闭时失去其选定的外观。 
UITableViewDelegate协议参考
链接地址: http://www.djcxy.com/p/49401.html上一篇: UITableview: How to Disable Selection for Some Rows but Not Others
下一篇: UITableView didSelectRowAtIndexPath: not being called on first tap
