So when I was testing my app, I am getting this crash in the console:
3 UIKit 0x32fe529e -[UIButtonContent setImage:] + 26
4 UIKit 0x32fe51dc -[UIButton setImage:forState:] + 136
5 App 0x0005ce20 -[MainView resetPicture] (MainView.mm:138)
So I checked MainView’s resetPicture and this is the code at or around line 138:
if ([myButton imageForState:UIControlStateNormal] != theImage) {
[myButton setImage:theImage forState:UIControlStateNormal];
}
Now I do this to theImage in the ViewDidLoad:
nib = [UIImage imageNamed:@"My-Image-Button.png"];
Now is there anything here that could be causing this issue?
Thanks!
Are you using ARC? If not, then you’d need to retain the UIImage you’re loading when storing it in an instance variable as your code shows. (Or use a property.) Otherwise, it could be deallocated by the time you get to resetPicture.