Reputation: 1436
I want to send a image to next scent.but failed.
here is my code
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"prepareForSegue start");
NSLog(@"count is %d",count);
//bigStyle1 is a NSArray,full of UIImage
//bigImage is a UIImageView outlet
if ([bigStyle1 objectAtIndex:count]==nil) {
NSLog(@"no array image");
}
viewController3.bigImage.image=[bigStyle1 objectAtIndex:count];
if (viewController3.bigImage.image==nil) {
NSLog(@"no controller image");
}
NSLog(@"secondToThird");
NSLog(@"prepareForSegue end");
}
here is Xcode's log
2013-03-12 15:15:38.683 animation[1876:f803] prepareForSegue start
2013-03-12 15:15:50.825 animation[1876:f803] count is 0
2013-03-12 15:17:10.829 animation[1876:f803] no controller image
It seems that the problem is in assignment of image.Why assignment failed?
UPDATE viewController3 isn't nil.But bigImage is nil.I don't know why.I actually connect bigImage to the image view
Upvotes: 0
Views: 65
Reputation: 386038
I suspect that you intend viewController3
to be the destination of the segue. In that case, you should be setting it like this:
viewController3 = segue.destinationViewController;
I further suspect that viewController3.bigImage
is a UIImageView
. If so, you have a problem because viewController3
hasn't loaded its view hierarchy by the time the system sends prepareForSegue:sender:
, so viewController3.bigImage
hasn't been set yet. It's nil, and setting a property on nil does nothing (with no warning or error message).
It would be better to give viewController3
an image
property directly, and store the image on that property. Then, in viewController3
's viewDidLoad
method, copy the image from that property to self.bigImage.image
.
Alternatively, you can cheese it by forcing viewController3
to load its view in prepareForSegue:sender:
just by asking it for its view:
[viewController3 view]; // forces it to load its view hierarchy if necessary
viewController3.bigImage.image = [bigStyle1 objectAtIndex:count];
Upvotes: 2