I have following code and when I call this method, it doesn’t change the image of the button although there are images in the resources.
-(void)changeButton:(NSString*)button withURL:(NSString*)url {
timetableURL = url;
UIImage *btnImage;
if ([button isEqual:@"Browser"]) {
btnImage = [UIImage imageNamed:@"browser-button.png"];
[safariBtn addTarget:self action:@selector(onSafariButtonPress:) forControlEvents:UIControlEventTouchUpInside];
}
else if ([button isEqual:@"Timetable"]) {
btnImage = [UIImage imageNamed:@"browser-timetable.png"];
[safariBtn addTarget:self action:@selector(onTimetableButtonPress:) forControlEvents:UIControlEventTouchUpInside];
}
[safariBtn setImage:btnImage forState:UIControlStateNormal];
[btnImage release];
}
UPDATED
FYI: It’s a button upside UIToolbar.
Some things that seem to be wrong with your code:
[btnImage release]
You’ve created that image using autorelease, you are not responsible for its release. This will most likely end up in weird stuff happening, i.e. what you encountered.
Are you sure that btnImage has contents after that if statement? is there a possibility that button is not equal to @”Browser” nor @”Timetable”?
Also, make sure the button is in its normal state.
Cheers