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

标签 ios iphone objective-c 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; 设置为灰色项目。

关于ios - UITableview:如何禁用某些行而不是其他行的选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2267993/

相关文章:

ios - 如何在 swift 的动态 tableView 中有多个单元格大小?

ios - 在 iPhone 上以编程方式发送短信

ios - 标尺应用程序如何在所有设备上保持准确?

iphone - 无法在邮件中找到 vcard 附件

iphone - AudioQueue读取输入音量

ios - 位置的自定义图标。可能吗?

ios - 使用xcode获取iPhone应用程序 View 中的所有元素

ios - 启用所有异常断点后始终在 App 委托(delegate)中停止

iphone - 带有标签栏的半透明覆盖

iphone - ios uiwebview 在 shouldstartloadwithrequest 时停止请求