Losing Hair - UIBarButton won't work after dismissing ViewController

So if the image picker appears and I cancel, everything is fine. However, when I choose an image, and the image picker view dismisses, I can’t select the “pick” button again, it won’t work or print anything to the console. I have no idea why. Here’s my code:

`class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var imagePickerView: UIImageView!

@IBAction func pickAnImage(sender: AnyObject) {
    selectImageSourceAlert()
    print("test")
}

override func viewDidLoad() {
    super.viewDidLoad()
}

func selectImageSourceAlert() {
    let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
    let userLibrary = UIAlertAction(title: "Photo Library", style: .Default) {
        _ in
        self.presentImagePicker(pickerStyle: .PhotoLibrary)
    }
    let useCamera = UIAlertAction(title: "Camera", style: .Default) {
        _ in
        // TODO: Check if camera isn't available, skip action
        let x = UIImagePickerController.isSourceTypeAvailable(.Camera)
        print(x)
        if x {
            self.presentImagePicker(pickerStyle: .Camera)
        } else {
            print("No camera available")
        }
        
    }
    let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
    
    alert.addAction(userLibrary)
    alert.addAction(useCamera)
    alert.addAction(cancelAction)
    
    presentViewController(alert, animated: true, completion: nil)
}

func presentImagePicker(pickerStyle style: UIImagePickerControllerSourceType) {
    let imagePicker = UIImagePickerController()
    imagePicker.sourceType = style
    imagePicker.allowsEditing = true
    imagePicker.delegate = self
    
    self.presentViewController(imagePicker, animated: true, completion: nil)
}

// MARK: - ImagePicker Protocol

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    
    if let image = info["UIImagePickerControllerEditedImage"] as? UIImage {
        imagePickerView.image = image
    }
    
    dismissViewControllerAnimated(true, completion: nil)
}

}

`

Hope you guys can help as I’ve been coming back to this for the past 2 days and still can’t figure it out.

I don’t know if this will help, but when I remove this code:

if let image = info["UIImagePickerControllerEditedImage"] as? UIImage { imagePickerView.image = image }

Everything works again. But when I add it back, the button’s function doesn’t work again.

Using your class and with a simple storyboard everything went fine. Can we have a screenshot of your storyboard or even of your app in your device ?

Update:

So I added a regular button at the top right corner and that one works even after adding an image. My suspicion is my first button doesn’t work because it is a UIBar Button Item. Here’s an image that might be helpful (made the image background red for clarity):

Any idea how to fix it with these additional insight?

Well, that is pretty weird to have the UIBarButtonItem disabled… If your project is not too personal or if you can reduce the issue to a test subject with only this ViewController, upload it and I’ll give it a look