Matt Cooper
Matt Cooper

Reputation: 2062

iOS 8 - UIBarButtonItem Push Segue overriding Action

This issue seems to be new with iOS 8, as I had this setup working in iOS 7 and it just started causing problems when I updated.

In Interface Builder, if I have a UIBarButtonItem that triggers a Show (Push) segue to another View Controller and is also connected to an action, the segue happens but the action is never called. If I try this with a regular button, both the segue and action are called. This happens with UIBarButtonItems both when they are in the Navigation Bar and in a standalone UIToolBar

Could anyone explain why this might be happening/offer a possible fix? Thanks

Upvotes: 0

Views: 239

Answers (2)

Mike Taverne
Mike Taverne

Reputation: 9362

I think the preferred way to do this is to implement prepareForSegue in your view controller:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if (segue.identifier == "MySegueIdentifier") {
    // pass data to next view
}
}

Where "MySegueIdentifier" is the name of the segue in your storyboard.

Upvotes: 1

WhoaItsAFactorial
WhoaItsAFactorial

Reputation: 3558

A fix would be to create a manual segue and call it from your action using -(void)performSegueWithIdentifier: sender:

Upvotes: 2

Related Questions