Disable selection of a single UITableViewCell

前端 未结 9 2103
迷失自我
迷失自我 2021-01-31 08:32

How do you disable selecting only a single cell in a UITableView? I have several, and I only want the last to be disabled.

9条回答
  •  佛祖请我去吃肉
    2021-01-31 09:00

    As I mentioned in another thread all the above methods are not solving the problem precisely. The correct way of disabling a cell is through the method

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    

    and in that method one has to use

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    

    which disables cell selection but still allows the user to interact with subviews of the cell such as a UISwitch.

提交回复
热议问题