I am trying to set the bigImage, cadImage, and number in my class IDViewController. But these are never set when I use the code below. Obviously these properties are synthesized properly, and are on a scene on my storyboard. Am I missing something here?
ViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"leftMainSegue"])
{
IDViewController *vc = [segue destinationViewController];
[vc.bigImage setImage:[UIImage imageNamed:@"1.png"]];
[vc.number setText:@"01"];
}
}
IDViewController.h
@interface IDViewController : UIViewController
{
UIImageView *bigImage;
UIImageView *cadImage;
UILabel *number;
}
@property (nonatomic) UIImageView *bigImage;
@property (nonatomic) UIImageView *cadImage;
@property (nonatomic) UILabel *number;
@end
Even though
IDViewControlleris initialized by the timeprepareForSegue:is called, it probably hasn’t loaded its view and therefore not the sub-views that you’re trying to update.You would be better to set the image and text into properties directly owned by the controller and then set them into the views in
viewDidLoad:.Something like…. (Warning! Not checked by compiler!)
In IDViewController.h:
In IDViewController.m:
In ViewController.m: