Question

I have this code:

- (void)viewDidLoad {
[super viewDidLoad];
landscape.image = [UIImage imageNamed:@"tenerife1.png"];
}

First, I created an UIImageView with IBOutlet. Landscape is pointing to that UIImageView. In InterfaceBuilder I told to show an specific image in that UIImageView. It never changes. I always see the image I specified in InterfaceBuilder. But I want to set it programmatically. How can I do this?

Was it helpful?

Solution

is it possible you did not have a custom view set up for that nib file? I had the same problem. I created a UIview subclass for that view controller, went into Interface Builder and set the view to that UIView subclass and then added an import header for the UIView into the Controller class. thats what did it for me

OTHER TIPS

Try calling setNeedsDisplay on the view after you change the image:

   [landscape setNeedsDisplay];

Add this code, it might help you:

-(void)viewDidAppear:(BOOL)animated 
{
landscape.image = [UIImage imageNamed:@"tenerife1.png"];
}

Don't forget about connection between imageview and File's Owner in InterfaceBuilder.

it's only you need after that:

landscape.image = [UIImage imageNamed:@"tenerife1.png"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top