我在一组 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/