set UIImageView.image in prepareForSegue

前端 未结 2 1279
[愿得一人]
[愿得一人] 2021-01-13 18:52

I want to segue to a photoViewController that has an UIImageView. In flickrTVC, I say:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{         


        
相关标签:
2条回答
  • 2021-01-13 19:06

    Call [vc view] before setting the o of the view

    0 讨论(0)
  • 2021-01-13 19:16

    Your destination view controller hasn't loaded its view hierarchy by the time your source view controller receives the prepareForSegue:sender: message. So your destination VC's _imageView variable is nil.

    The recommended approach is to store the image (or, probably even better, the image file name) as a property of the destination VC, and then set the image view's image in the destination VC's viewDidLoad or viewWillAppear: method.

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