0
votes

In my UITableViewController, I have two sections. In I can select only one item from section 1 but 1 or more from section 2. I implemented Cell Accessory type to toggle between .CheckMark and .None

I cannot get it to have 1 selection for section 1 but multi selection for section 2.

Any idea how to implement these perhaps with tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) and tableView(tableView: UITableView, didRowAtIndexPath indexPath: NSIndexPath)

2

2 Answers

0
votes

One idea can be you set self.tableView.allowsMultipleSelection = YES; property in the tableview

Store the section 1 selection value in a variable
Section 2 value in array

In the didSelectRowAtIndexPath you check for the section and if it's section 1 remove/deselect the previous one value stored in the variable one and select/store the new one

If it's section 2 you can select/deselect the selected value in array and on cell by UITableViewCellAccessoryType

if (cell?.accessoryType == UITableViewCellAccessoryType.Checkmark){

    cell!.accessoryType = UITableViewCellAccessoryType.None;

}else{

    cell!.accessoryType = UITableViewCellAccessoryType.Checkmark;

}

If you want you may remove the value in both the section in didDeselectRowAtIndexPath, but that may not require if you write select/deselect code in didSelectRowAtIndexPath

0
votes

You can accomplish this task following the below approach.

Take a global variable and an array. Save required values at didSelectRowAtIndexPath and reload the table. I am sharing the demo project for the same. I have created and tested it. Its working fine. Here is the link: Link