UIImageView not displaying image when property is set too early

Posted by Undeadlegion on Stack Overflow See other posts from Stack Overflow or by Undeadlegion
Published on 2011-02-10T07:23:10Z Indexed on 2011/02/10 7:25 UTC
Read the original article Hit count: 137

Filed under:
|

I have an image I want to display inside a UIView. In Interface Builder, the UIView is the root and a UIImageView is its child.

The view is connected to view controller's view outlet, and the image view is connected to the image view outlet:

@property (nonatomic, retain) IBOutlet UIImageView *imageView;

If I try to set the image property of UIImageView before it's visible, the image doesn't show up.

TestView *testView = [[TestView alloc] initWithNibName:@"TestView" bundle:nil];
testview.imageView.image = [logos objectAtIndex:indexPath.row];
[self.navigationController pushViewController:testView animated:YES];

If, however, I pass the image to the controller and set the image property in view did load, the image becomes visible.

TestView *testView = [[TestView alloc] initWithNibName:@"TestView" bundle:nil];
testview.image = [logos objectAtIndex:indexPath.row];
[self.navigationController pushViewController:testView animated:YES];

- (void)viewDidLoad
{
    [super viewDidLoad];
    imageView.image = image;
}

What is causing the image to not show up in the first scenario?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c