I am getting "EXC_BAD_ACCESS
" when touch the button to call the button action.
#import "TestViewController.h"
@implementation TestViewController
- (id)init
{
self = [super init];
if (self)
{
self.title=@"IOS5 and Xoced 4.2";
UIButton *button=[[UIButton alloc]initWithFrame:CGRectMake(9,6,100,100)];
button.backgroundColor=[UIColor greenColor];
[button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview: button];
}
return self;
}
-(void)viewWillAppear:(BOOL)animated
{
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]initWithTitle:@"Add"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(addAction)];
self.navigationItem.rightBarButtonItem = addButton;
}
-(void)buttonAction
{
printf("Hi i am in buttonAction method");
}
-(void)addAction
{
printf("Hi i am in addAction method");
}
I used ARC enbled in this project. When I touch the UIBarButtonItem or UIButton I am getting below error.
TestXcode4[2470:207] -[__NSCFString addAction]: unrecognized selector sent to instance 0x6827b00
Please help me out of this.