I’m using an if statement to set a UIImageView‘s image depending on the value of a variable. This is the statement:
- (void)configureView
{
if (self.detailItem) {
if ([detailItem isEqualToNumber:[NSNumber numberWithInt:0]]) {
[mapImageView setImage:[UIImage imageNamed:@"0.jpg"]];
NSLog(@"derp");
}
}
}
“derp” gets printed but the UIImageView‘s image won’t change… If I put the setImage: statement in viewDidLoad it works fine. What am I doing wrongly?
My guess is you’re calling the
configureViewmethod from a view controller’s init method.At that point the view controller’s view has not been loaded, and the outlets for its subviews will still be
nil.Calling it from any of:
will work.
Try assigning
put a breakpoint there, and then look at the value in
image, to make it’s being assigned correctly.