I have a searchController and tableView in A ViewController where I can search any item from tableView and select that item. I’m saving all selected items in other ViewController B.
Now when I again redirect to A VC where I can see my selected items, I want to deselect some items from selected cells, but I’m not able to deselect the selected cell all other deselected cells I can select without a problem.
When I tap on the selected cell to deselect, I can see it is not calling the below method.
tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath)
In my viewDidLoad
I have the following properties
tableView.isEditing = true
tableView.allowsMultipleSelectionDuringEditing = true
And I’m not using any custom cells. Please help me if you have any solution. TIA.
2
Answers
I have resolved this issue the problem was related to the way I was setting the cell selection I have added the following line in the
cellForRow
method.You can control the selection using your table view data source model.
assume you have an array of objects ex:
var arr:[YourObject] = []
then add a variable to YourObject ex:
var isSelected: Bool = false
in the
cellForRow
method, check your current item selection status and change the cell selection style.and finally, in
didSelectRow
method, change your current selected objectisSelected
variable status, then reload table view