PengOne2
PengOne2

Reputation: 31

bug in my BarButton

I have a bug in my code and I cannot seem to find it! I've created a button called addButton programatically and set its selector to add—but the app crashes in the simulator every time the button is pressed. Here is my code.

-(void)viewDidLoad{
UIBarButtonItem *addButton = [[UIBarButtonItem alloc]  
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self   
action:@selector(add:)];
self.navigationItem.rightBarButtonItem = addButton;
[addButton release];
}

and the code for the add button is :

- (IBAction)add
{
MyDetailViewController * detail = [[MyDetailViewController alloc]init];
detail.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:detail animated:YES];
//[detail.text becomeFirstResponder];

[detail release];

}

Thanks for the help guys :D

Upvotes: 0

Views: 62

Answers (1)

Suhail Patel
Suhail Patel

Reputation: 13694

Your add selector has a colon at the end which means it is trying to use an add method with a parameter but your add method does not expect a parameter object. You need to remove the colon from your selector by changing your Bar Button Item allocation to this:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add)];

Upvotes: 2

Related Questions