Can I trigger a segue from a UIBarButtonItem?

10,311

Solution 1

You can call a segue yourself using

[self performSegueWithIdentifier: @"SegueToScene1" sender: self];

Solution 2

I think you may be using a UIButton instead of a UIBarButtonItem object. I was just having the same problem but I had initially dragged a standard button to the toolbar. When I changed it the storyboard segue worked as expected.

Solution 3

I set up a modal segue triggered from a UIBarButtonItem inside a UIToolbar in a sample project, it works fine.

Share:
10,311
Undistraction
Author by

Undistraction

Updated on June 30, 2022

Comments

  • Undistraction
    Undistraction almost 2 years

    I have a toolbar in one of my storyboard's scenes. The toolbar contains a single UIBarButtonItem. I want a Touch Down on the button to trigger a segue to a new UIViewController. If I drag over to the viewController and choose 'Modal' from the popup, the segue is not triggered. 'prepareForSegue' is never called. In the Utility panel under 'Referencing Storyboard Segues' the Button has an exclamation mark next to its name and shows the following on rollover:

    'null' is not a valid controller containment key path.

    If I drag over from the button and select 'Push' from the popup, I do not get this warning , however again the segue doesn't work and prepareForSegue is never called.

    If I hook up either type of segue to a UIButton (outside a Toolbar), the segue works fine in both cases. So it appears to me that Segues do not work when triggered from Toolbar items.

    Can anyone confirm this or point out what I'm doing wrong?