Crash when pushing to another controller after `didFinishPickingMediaWithInfo`

后端 未结 2 1551
面向向阳花
面向向阳花 2021-01-26 09:56

I\'m trying to have the app go to a different view controller after the user chooses a photo from the picker.

func imagePickerController(_ picker: UIImagePickerC         


        
相关标签:
2条回答
  • 2021-01-26 10:44

    add this to your function

    dismiss(animated:true, completion: nil)
    

    In the completion, you can define a closure that does whatever you want.

    0 讨论(0)
  • 2021-01-26 10:59

    The primary cause of your issue is that you are trying to access the outlets of the view controller too soon. The view controller's views and outlets are not created and assigned immediately after instantiating the view controller.

    It's also poor design to attempt to directly access the views of a view controller from code outside of that view controller. The proper solution, in this case, is to add a UIImage property that you can set. Then let the view controller update its own image view based on the value of that image property at the proper time (such as in viewDidLoad).

    0 讨论(0)
提交回复
热议问题