Reputation: 1853
i tried to define a UIBarButtonItem programatically. it showed up in the navBar as expected. but it didn´t call the action until i went to the IB and dragged an bar button item into the navigation controller object and assigned it with the didTapSearch action.
i thought it´s possible to define UIBarButtonItems programatically only, without any additional IB work. or is that only possible if the navigation controller and/or the view controller was created programatically as well?
or did i miss to set a delegate in my code again?
UIBarButtonItem *searchBtn = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch target:self action:@selector(didTapSearch:)] autorelease];
self.navigationItem.rightBarButtonItem = searchBtn;
Upvotes: 2
Views: 2436
Reputation: 638
try this way instead in the header, declare the barButtonItem
proximityButton= [[UIBarButtonItem alloc]
initWithTitle:@"Nearby Locations"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(addToProximity)];
self.navigationItem.leftBarButtonItem = proximityButton;
and you can take out the :(id)sender part of the action
Upvotes: 1
Reputation: 31722
You could specific the action:
method programatically as you have done with your UIBarButtonItem
.
Implement action method in the class of object which you specified with target:
.
-(void) didTapSearch:(id) sender
{
UIBarButtonItem *searchBtn = (UIBarButtonItem*)sender;
}
Upvotes: 0