Disable selection of a single UITableViewCell

前端 未结 9 2083
迷失自我
迷失自我 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:18

    To stop just some cells being selected use:

    cell.userInteractionEnabled = NO;
    

    As well as preventing selection, this also stops tableView:didSelectRowAtIndexPath: being called for the cells that have it set. It will also make voiceover treat it the same as a dimmed button (which may or may not be what you want).

    Note that if you have interactive elements in the cell (ie. switches/buttons), you'll need to use cell.selectionStyle = UITableViewCellSelectionStyleNone; instead and then make sure to ignore taps on the cell in tableView:didSelectRowAtIndexPath:.

提交回复
热议问题