0

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

Matt Stein
  • 3,053
  • 1
  • 19
  • 35
PengOne2
  • 31
  • 1
  • 9

1 Answers1

2

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)];
Suhail Patel
  • 13,644
  • 2
  • 44
  • 49