Reputation: 37581
I've added a UIImageVIew to my view and if I specify the image to use within IB then it gets displayed correctly, but if I instead try to add the image programatically then it doesn't display.
I cleared out the image to load from IB and added the following code:
- (void)viewDidLoad
{
[super viewDidLoad];
UIImage* image = [UIImage imageNamed:@"pic1.png"];
UIImageView *iv = [[UIImageView alloc] initWithImage: image];
iv.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
iv.contentMode = UIViewContentModeCenter;
self.slideshowView = iv;
}
self.slideshowView is an outlet connected to the image view.
I can confirm that image and iv are both non null when it executes.
Upvotes: 1
Views: 87
Reputation: 24910
Instead of creating a new UIImageView, set the outlet's image property. The problem here is that your new UIImageView does not have a frame within your super view and you're repointing the outlet to the new imageview you created.
self.slideshowView.image = [UIImage imageNamed:@"pic1.png"];
Upvotes: 1