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.