Interact with a view controller from another view controller
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 loop.
Code:
- (IBAction)buttonClicked:(id)sender {
iPhotoViewControlle开发者_如何学JAVAr *photo = [[iPhotoViewController alloc] initWithNibName:@"iPhotoViewController" bundle:nil] ;
if (photo.mainView.image)
{
but = (UIButton *) sender;
self.selectedImage = [_images objectAtIndex:but.tag];
iPhoto2AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[delegate.navController popViewControllerAnimated:YES];
[photo release];
}
Thanks, Praveen
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
did you define both
@property(nonatomic, retain) UIImage * image; // (or UIImageView *)
in your .h and
@synthesize image;
in your .m ?
精彩评论