I have a app that has multiple buttons that are all assigned images in the interface builder. I then change there images during the application. What i want to know how would you is to change the images back to the original image….I did it by the following code but it keeps crashing the app
- (IBAction)resetCards
{
NSString *cardImage = [[NSString alloc] initWithFormat:@"CardBackground.png"];
UIImage *buttonImage = [UIImage imageNamed:cardImage];
[holdCardOne setImage:buttonImage forState:UIControlStateNormal];
[holdCardTwo setImage:buttonImage forState:UIControlStateNormal];
[flopCardOne setImage:buttonImage forState:UIControlStateNormal];
[flopCardTwo setImage:buttonImage forState:UIControlStateNormal];
[flopCardThree setImage:buttonImage forState:UIControlStateNormal];
[turnCard setImage:buttonImage forState:UIControlStateNormal];
[riverCard setImage:buttonImage forState:UIControlStateNormal];
[cardImage release];
[buttonImage release];
}
Don’t call
[buttonImage release]— it is being autoreleased.Usually only call release if you call alloc, copy, or retain. Always check the documentation for a message that returns an object if you are unsure, but normal Objective-C process is to return objects that autorelease.