Reputation: 2134
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
Upvotes: 0
Views: 102
Reputation: 31016
Even though IDViewController
is initialized by the time prepareForSegue:
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:
@property (nonatomic, strong) UIImage *inputImage;
@property (nonatomic, strong) NSString *inputString;
In IDViewController.m:
@synthesize inputImage = _inputImage;
@synthesize inputString = _inputString;
...
- (void)viewDidLoad {
...
self.bigImage.image = self.inputImage;
self.number.text = self.inputString;
...
}
In ViewController.m:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
...
vc.inputImage = [UIImage imageNamed:@"1.png"];
vc.inputString = @"01";
...
}
Upvotes: 1