Interact with a view controller from another view controller

后端 未结 2 681
一整个雨季
一整个雨季 2021-01-22 20:57

I want my view controller to check if there is an image on another view controller when i click a button. But as of now even there is an image the simulator does not execute the

相关标签:
2条回答
  • 2021-01-22 21:21

    did you define both

    @property(nonatomic, retain) UIImage * image;  // (or UIImageView *)
    

    in your .h and

    @synthesize image;
    

    in your .m ?

    0 讨论(0)
  • 2021-01-22 21:37

    You are creating a new instance of iPhotoViewController which means that the image you want to use must be available in the nib file. And being available in the nib file means that it is available in your project so creating a new iPhotoViewController just to see if that image is there seems a bit strange.

    Is there perhaps already an instance of this iPhotoViewController somewhere where you have a loaded an image? If so that is the instance you need to check.

    But perhaps you are testing things and have set an image in the nib and just want to make sure it works. In that case, the reason photo.mainView.image is not set is because you have only created the view controller but the view as not yet been loaded and setup from the nib. To fake this you need to access the view property of the controller before checking if the image is set.

    iPhotoViewController *photo = [[iPhotoViewController alloc] initWithNibName:@"iPhotoViewController" bundle:nil] ;
    
    [photo view];
    if (photo.mainView.image) {
    // continue as before
    
    0 讨论(0)
提交回复
热议问题