So, while my tableview's in edit mode some buttons on a toolbar are disabled and enabled depending on how many cells are selected. Here's the script that handles part of that:
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
var selected : Int = 0
if tableView.indexPathsForSelectedRows?.count != nil{ //Used to overcome optionals
selected = tableView.indexPathsForSelectedRows!.count
}
if tableView.indexPathsForSelectedRows?.count == nil{ //Used for testing
selected = 0
}
if((tableView.isEditing == true) && (tableView.indexPathsForSelectedRows?.count == 1)){
toolBar.items![0].isEnabled = true
toolBar.items![2].isEnabled = true
toolBar.items![4].isEnabled = true
}
if((tableView.isEditing == true) && (selected == 0)){
toolBar.items![0].isEnabled = false
toolBar.items![2].isEnabled = false
toolBar.items![4].isEnabled = false
}
if ((tableView.isEditing == true) && (selected >= 2)){
toolBar.items![0].isEnabled = true
toolBar.items![2].isEnabled = false
toolBar.items![4].isEnabled = true
}
else{
toolBar.items![0].isEnabled = true
toolBar.items![2].isEnabled = true
toolBar.items![4].isEnabled = true
}
}Line 20-22 doesn't work. I set isEnabled to false on all of the buttons, but they won't disable. Everything else works but this section. I printed the isEnabled value for each item in the toolbar and the console said the buttons were disabled. BUT THEY WEREN'T! Does anyone have any ideas on why this is happening?