Add UIImagePickerControllerDelegate, UINavigationControllerDelegate
at top of the class.
Before viewDidLoad()
var picker = UIImagePickerController()
In viewDidLoad()
or any function that you want to use image picker
picker.delegate = self
Add some function for catch event
// What to do when the picker returns with a photo
//Use image that user pick from library
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
let chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage
dismissViewControllerAnimated(true, completion: nil)
addAvatar(chosenImage)
}
// What to do if the image picker cancels.
// some code for do anything when user cancel to import image
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
dismissViewControllerAnimated(true, completion: {() in
})
}
Leave a comment