Crash when pushing to another controller after `didFinishPickingMediaWithInfo`

后端 未结 2 1550
面向向阳花
面向向阳花 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: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).

提交回复
热议问题