Question: I have an action button in my iOS application (using Swift 3), which I guess is technically a toolbar item.

I presently disable the button in viewWillAppear() with

```
actionButton.isEnabled = false

```

I then try to enable it after an image has been selected:

```
func imagePickerController(_: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    if let image = info[UIImagePickerControllerOriginalImage] as? UIImage {
        imageView.image = image
        imageView.contentMode = .scaleAspectFit
    }
    dismiss(animated: true, completion: nil)
    actionButton.isEnabled = true
    print("selected an image in picker")
}

```

And I can see that my print statement occurs as well as the image being selected and activity view controller dismissing, just as expected. HOWEVER, my actionButton stays disabled.

Any ideas why? I'm very new to Swift!

Answer: 
`viewWillAppear()` is called every time, before your view controller loads. When you dismiss your imagePicker, and go back to presenting your original viewController that `viewWillAppear()` would be called again, and it would override your `actionButton.isEnable = true` to being false again. If I were you, I would disable the button in `viewDidLoad()`, which is called only once.
try to execute the code that changes the UI in the main thread like this:

```
DispatchQueue.main.async {
    actionButton.isEnabled = true
}

```