Reputation: 83
Sorry, Im fairly new to this and was wondering how to create an edit button as a bar button item...
What I did is I placed a bar button item on the right side of the navigation bar and created an
- (IBAction)editButton:(id)sender;
I tried to hook this up to the button, but the option doesn't show up. How do I get this button to do something when its clicked?
Thank you for your help!
Upvotes: 0
Views: 118
Reputation: 2165
CTRL + click on the bar button item, and drag it to the impementation file of the view controller, viewController.m. Then you would be able to create an IBAction method.
Upvotes: 2
Reputation: 9246
Ok, here is the way. If you have a view controller "first" and you navigate another view controller "second" by pushing a button or etc. you need to do some work. First you need to create a BarButtonItem in "second" view controller's ViewDidLoad method like this;
UIBarButtonItem *btnBack = [[UIBarButtonItem alloc]
initWithTitle:@"Back"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(OnClick_btnBack:)];
self.navigationItem.leftBarButtonItem = btnBack;
[btnBack release];
After you do that, you need to write to code for "btnBack" action in the same .m file like this;
-(IBAction)OnClick_btnBack:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
//[self.navigationController pushViewController:self.navigationController.parentViewController animated:YES];
}
That's all.
Upvotes: 2