I need to make a presentation that works like pages
with a popup in which I can select a photo from my library or create a new one.
I currently have a ViewController presented as a Popover. In the ViewController, I inserted a ContainerView, and I declared that its class is UIImageViewController. This shows me a photo library, but I can not find anything in: My ViewController is presented as a Popover .
When I select a photo, nothing happens. I tried to put some functions
(func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!))
in my ViewController, but it does not work. I read that UIImagePickerController does not support subclasses, so how do pages do this?
Here is my ViewController code:
import UIKit class MenuAddResources: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate { var newMedia: Bool? let imagePicker = UIImagePickerController() @IBAction func takePhoto(sender: AnyObject) { if(UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)){ //load the camera interface let picker : UIImagePickerController = UIImagePickerController() picker.sourceType = UIImagePickerControllerSourceType.Camera picker.delegate = self picker.allowsEditing = false self.presentViewController(picker, animated: true, completion: nil) self.newMedia = true } else{ //no camera available let alert = UIAlertController(title: NSLocalizedString("ERROR", comment: ""), message: NSLocalizedString("NO_CAMERA", comment: ""), preferredStyle: .Alert) alert.addAction(UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .Default, handler: {(alertAction)in alert.dismissViewControllerAnimated(true, completion: nil) })) self.presentViewController(alert, animated: true, completion: nil) } } override func viewDidLoad() { super.viewDidLoad() } func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo:UnsafePointer<Void>) { if error != nil { let alert = UIAlertController(title: NSLocalizedString("ERROR", comment: ""), message: NSLocalizedString("IMAGE_SAVE_FAILED", comment: ""), preferredStyle: UIAlertControllerStyle.Alert) let cancelAction = UIAlertAction(title: NSLocalizedString("OK", comment: ""), style: .Cancel, handler: nil) alert.addAction(cancelAction) self.presentViewController(alert, animated: true, completion: nil) } } func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: NSDictionary!){ self.dismissViewControllerAnimated(true, completion: { () -> Void in }) // Let store the image let now:Int = Int(NSDate().timeIntervalSince1970) let imageData = UIImageJPEGRepresentation(image, 85) //imageData?.writeToFile(documentsDirectory + "/\(now).jpg", atomically: true) print(imageData) /* will do stuff with the image */ } func imagePickerControllerDidCancel(picker: UIImagePickerController) { self.dismissViewControllerAnimated(true, completion: nil) } }