I would like that appeared the Image on the second view with this but I can´t see any photo I don´t know why. I did this:
FirstClassViewController.m:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowCover"]) {
MovieImageViewController *photo = [segue destinationViewController];
photo.cover.image = [UIImage imageNamed:@"helloWorld.jpg"];
}
}
SecondClassViewController.m:
- (void)viewDidLoad
{
[super viewDidLoad];
[self cover];
}
The cover is a property UIImageView that I created on the SecondClassViewController.
When you call prepareForSegue:sender:
the outlets from your destinationViewController are not set yet. This means that your photo.cover
property is still nil.
What you can do is create a UIImage
property on your MovieImageViewController
and do something like:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"ShowCover"]) {
MovieImageViewController *photo = [segue destinationViewController];
photo.image = [UIImage imageNamed:@"helloWorld.jpg"];
}
}
and on your -viewDidLoad
method:
- (void)viewDidLoad
{
[super viewDidLoad];
self.cover.image = self.image;
}
I'm guessing that "cover" is an image view property of your MovieImageViewController class? If so, don't do that.
You should treat another view controllers views as private.
Instead, set up an image property in your MovieImageViewController class. Set THAT in your prepareForSegue method, and then in your MovieImageViewController's viewWillAppear:animated method, install the image into your "cover" image view. Problem solved.
EDIT: To clarify
Add the following to the header (.h) file for your MovieImageViewController class:
@interface MovieImageViewController
//This property is the line to add
@property (nonatomic, strong) UIImage *coverImage;
//your other stuff goes here.
@end
Then in your .m file:
@implementation MovieImageViewController
- (void) viewWillAppear: animated
{
[super viewWillAppear: animated];
//Add the following code to your viewWillAppear:animated method
if (self.coverImage != nil)
self.cover.image = self.coverImage;
}
@end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With