Per Larsen
Per Larsen

Reputation: 1189

Why a bar button item on a NavigationViewController won't trigger an IBAction

I have a pretty basic app I am working on that uses a navigation view controller system. One of my view is a table view that I added a bar button to in the story board. This bar button is just a basic add button for adding a new item to the table view. I identified the segue for use in my prepare for segue method and then I created an IBAction for the button as well.

The segue pushes to my next view just fine and passed my desired object, but the action never triggered. I ended up having to put the code for the IBAction in my prepare for segue method to get it to work.

I'm just wondering why IBAction was never triggered.

Upvotes: 0

Views: 2572

Answers (1)

NSTJ
NSTJ

Reputation: 3888

1) remove the segueNamedFoo you have created from the button to the destination view controller

2) create a manual segueNamedFoo push segue by CTRL-dragging from the leftmost small icon at the base of the origin view controller to the destination view controller

3) in your - (IBAction)doStuffBeforeSegue:(id)sender method which you have connected to your button perform the tasks which you want and then call [self performSegueWithIdentifier:@"segueNamedFoo"]

Upvotes: 3

Related Questions