ios - UITableview:如何禁用某些行而不是其他行的选择

我在一组 tableview 中显示从 XML 解析的内容。我想禁用它的点击事件(我根本不能点击它) 该表包含两个组。我只想禁用第一组的选择,而不是第二组。单击第二组的第一行 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

禁用单元格的选择属性:(点击单元格时)

cell.selectionStyle = UITableViewCellSelectionStyleNone;

要能够选择(点击)单元格:(点击单元格)

// Default style
cell.selectionStyle = UITableViewCellSelectionStyleBlue;

// Gray style
cell.selectionStyle = UITableViewCellSelectionStyleGray;

请注意,具有 selectionStyle = UITableViewCellSelectionStyleNone; 的单元格在用户触摸时仍会导致 UI 调用 didSelectRowAtIndexPath。为避免这种情况,请按照以下建议进行设置。

cell.userInteractionEnabled = NO;

相反。另请注意,您可能希望将 cell.textLabel.enabled = NO; 设置为灰色项目。

https://stackoverflow.com/questions/2267993/

相关文章:

objective-c - block 声明语法列表

ios - UIActivityViewController 在 iOS 8 iPad 上崩溃

ios - 如何向 UIView 添加触摸事件?

ios - Objective-C 中的字符串替换

objective-c - #pragma 标记的意义​​是什么?为什么我们需要#pragma 标记

objective-c - iOS7 无法隐藏状态栏

ios - cocoa touch : How To Change UIView's Border

iphone - 开发一个 iPhone 应用程序需要多少钱?

ios - UIScrollView 以编程方式滚动到底部

ios - 退出 iPhone 应用程序的正确方法?