UIBarButtonItem won't disable

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?

Ended up finding a temp workaround.


toolBar.isUserInteractionEnabled = false
trashButton.tintColor = UIColor(displayP3Red: 0.0, green: 0.05, blue: 0.124, alpha: 0.25)
 renameButton.tintColor = UIColor(displayP3Red: 0.0, green: 0.05, blue: 0.124, alpha: 0.25)
shareButton.tintColor = UIColor(displayP3Red: 0.0, green: 0.05, blue: 0.124, alpha: 0.25)


Simply disable all input and fade out the buttons.

UIBarButtonItem won't disable
 
 
Q