I'm getting the dreaded EXC_BAD_ACCESS error when I'm trying to set an
image on a UIButton.
I read the Apple doc on memory management and still can't figure out
what I'm doing wrong. I've verified my images are all accessible and working in my Resources folder.
I've narrowed it down to the exact line of code that's causing the
error. If you can help me figure out what I'm doing wrong and how to fix
it, I'll be eternally grateful
I have a very simplified version of my code:
Here's my Header File:
MyController.h
And here's my implementation file. I noted in the comments below which line causes the error:
image on a UIButton.
I read the Apple doc on memory management and still can't figure out
what I'm doing wrong. I've verified my images are all accessible and working in my Resources folder.
I've narrowed it down to the exact line of code that's causing the
error. If you can help me figure out what I'm doing wrong and how to fix
it, I'll be eternally grateful
I have a very simplified version of my code:
Here's my Header File:
MyController.h
Code:
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface MyController : UIViewController {
IBOutlet UIButton *button1;
}
@property (nonatomic, retain) UIButton *button1;
- (IBAction)clickedAButton:(id)sender;
- (NSString *)doSomething:(int)someNumber;
@end
And here's my implementation file. I noted in the comments below which line causes the error:
Code:
#import "MyController.h"
@implementation MyController
@synthesize button1;
- (IBAction)clickedAButton:(id)sender{
NSString *myString;
[sender setTitleColor:[UIColor redColor] forState:UIControlStateNormal];//This line works perfectly
[sender setImage:[UIImage imageNamed:@"Red.png"] forState:UIControlStateNormal]; //This line works Perfectly
myString = [self doSomething:1];
}
- (NSString *)doSomething:(int)someNumber {
[button1 setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];//This line works perfectly
[button1 setImage:[UIImage imageNamed:@"Blue.png"] forState:UIControlStateNormal];//This line causes the EXC_BAD_ACCESS Error
return @"didSomething";
}