I created a single view project in xcode 4. I added a navigation bar item object. In that I added a navigation bar button called “Done”. All using he Xcode drag and drop. To that button I attached a very simple IBAction
- (IBAction) newContactDoneBtn:(id)sender
{
NSLog(@"INSIDE newContactDoneBtn");
}
In the “sent actions” I connected that Done button with this newContactDoneBtn IBAction. So far so good. If I compile and run it works fine i.e. I see the message log.
Now here’s the kicker, if to that Done button I attach a modal storyboard i.e. when the user clicks on that Done button it takes them to another view controller … my custom IBaction “newContactDoneBtn” never gets called and I see the new screen. Now why would that be?
An easy example to visualize all this would be the “Done” button in iphone contacts app. When you click on adding a new contact there is the done button up there, you enter something in the fields and hit done, it takes you to another view controller and it did add that new contact to the address book.
It maybe a limitation of UIBarButtonItem but can anyone tell me if I missed something?
Adding the segue to the button presumably overrides any action you had applied to it. Is the action still connected in interface builder after you’ve set the segue?
Why would you want both things to happen? What order should they be done in if you were able to fire an action and a segue simultaneously?
If you just want to call the modal view controller, then connecting the segue does that for you without needing to write any code. You can run anything you need in the
prepareForSegue:method of your view controller. Alternatively, you can manually present the modal controller from your action method.