Here is my UIBarButton
:
[self.navigationItem setLeftBarButtonItem:[[UIBarButtonItem alloc]
initWithTitle:@"+ Contact"
style:UIBarButtonItemStylePlain
target:nil
action:@selector(showPicker:)] animated:YES];
Here is the code it's supposed to launch:
- (void)showPicker:(id)sender {
ABPeoplePickerNavigationController *picker =
[[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
When I launch the app and click on the '+ Contact' UIBarButton
, nothing happens. No errors, nada. I put in a breakpoint, and it never reaches the method referenced by the selector.
Am I doing something wrong in the way I'm calling the selector?
Thanks!
For those that are still having trouble with this, here is another solution that I have found: Instead of doing this:
Try something like this:
*Make sure you've added this
UIBarButtonItem
in the toolbar in Storyboard. (Or you could just programmatically create your ownUIBarButtonItem
before this set of code and add it to the items array of the UIToolbar.)Somehow, ageektrapped's solution did not work for me, although his solution is what I would rather use. Maybe someone more knowledgeable about UIBarButtonItems could comment on why one solution worked over the other?
The declaration of your button is missing something, namely the
target
parameter. Try this:This assumes that
showPicker:
is in fact in the same class that's adding the button to the navigation item.The
target
parameter is the instance that should handle the event.The "target" should be the object the selector belongs to, instead of nil.