UIImagePickerController to import Image

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

UIImagePickerController to import Image



i want import image in ios from library but i have error



value of type 'viewcontroller' has no member 'present'


class ViewController: UIViewController

override func viewDidLoad()
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.



@IBAction func Alert(sender: AnyObject)

let nextController = UIImagePickerController()
self.present(nextController, animated: true, completion: nil)






1 Answer
1



Here's my stripped working code. I use two pickers - one for camera, one for library - because of some odd iOS bug with tint color. To avoid "massive view controller" issues, I tend to move everything possible related to a a UIImagePickerController into a separate file and extension.


UIImagePickerController


class OpenViewController: UIViewController

let pickerLibrary = UIImagePickerController()
override func viewDidLoad()
super.viewDidLoad()
pickerLibrary.delegate = self




extension OpenViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate

@objc func showImagePicker()
pickerLibrary.allowsEditing = false
pickerLibrary.sourceType = .photoLibrary
present(pickerLibrary,
animated: true,
completion: nil)
pickerLibrary.popoverPresentationController?.sourceView = self.view

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage
dismiss(animated: true, completion: nil)

func imagePickerControllerDidCancel(_ picker: UIImagePickerController)
dismiss(animated: false, completion: nil)




While the present code looks correct, I notice several things you didn't post in your code. Maybe because you just didn't post it, but I would definitely check these things:


present


ViewController


ViewController.view


UIImagePickerControllerDelegate, UINavigationControllerDelegate



Now as your error suggests, something else is likely the issue - a UIViewController can present another view controller. In this case you've given us no way to duplicate that error. In other words, I'm assuming that (1) You are seeing a UIButton attached to Alert() - BTW, Swift conventions use lower case for that - and (2) You've proven that when that button is tapped, `Alert() is actually executed.


UIViewController


present


UIButton


Alert()






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

Trying to Print Gridster Items to PDF without overlapping contents

Hystrix command on request collapser fallback