Select multiple rows in tableview and tick the selected ones

前端 未结 5 1685
北海茫月
北海茫月 2020-12-12 17:34

I\'m loading a tableView from a plist file. This works with no problems. I just simply want to \"tick\" the selected rows. At the moment, with my code it didn\'t work as des

5条回答
  •  孤城傲影
    2020-12-12 17:58

    First of all, go to your Storyboard and select you tableview and in the Attributes Inspector, set Selection to Multiple Selection.

    Attributes Inspector with multiple selection

    Then, override the setSelected(_ selected: Bool, animated: Bool) function in the subclass of UITableViewCell.

    override func setSelected(_ selected: Bool, animated: Bool) {
            super.setSelected(selected, animated: animated)
            accessoryType = selected ? UITableViewCellAccessoryType.checkmark : UITableViewCellAccessoryType.none
        }
    

提交回复
热议问题