UITableview:如何禁用某些行而不是其他行的选择 [英] UITableview: How to Disable Selection for Some Rows but Not Others

查看:84
本文介绍了UITableview:如何禁用某些行而不是其他行的选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在显示从XML解析的组 tableview 内容。我想禁用它上面的click事件(我根本不应该单击它)该表包含两个组。我想禁用第一组的选择,但不禁用第二组。单击第二组的第一行导航到我的管播放器视图

I am displaying in a group tableview contents parsed from XML. I want to disable the click event on it (I should not be able to click it at all) The table contains two groups. I want to disable selection for the first group only but not the second group. Clicking the first row of second group navigates to my tube player view.

如何才能选择特定的组或行?

How can I make just specific groups or rows selectable?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if(indexPath.section!=0)
    if(indexPath.row==0)    

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:tubeUrl]];   
}

谢谢。

推荐答案

您只需将此代码放入 cellForRowAtIndexPath

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

To disable the cell's selection property:(While tapping the cell).

cell.selectionStyle =.none

为了能够选择(点击)单元格:(点击单元格)。

To enable being able to select (tap) thecell:(tapping the cell).

// Default style
cell.selectionStyle =.blue

// Gray style
cell.selectionStyle =.gray

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

Note that a cell with selectionStyle = UITableViewCellSelectionStyleNone will still cause the UI to call didSelectRowAtIndexPath when touched by the user. To avoid this, do as suggested below and set.

cell.isUserInteractionEnabled = false

。另请注意,您可能需要设置 cell.textLabel?.isEnabled = false 以使项目变灰。

instead. Also note you may want to set cell.textLabel?.isEnabled = false to grey out the item.

这篇关于UITableview:如何禁用某些行而不是其他行的选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆