I'm creating a popoverSegue from a new view controller and want to push a third view controller onto the original stack. This is how I'm creating the application:
Single View Application
Use Storyboards
MainStoryboard.storyboard
file.Title
and Identifier
to initialView
, then select Editor->Embed In->Navigation Controller
View Controller
objects from the Objects Library onto the canvasTitle
and Identifier
of the new View Controllers to: popoverView
and newView
.Round Rect Button
object from the Object Library to initialView
and popoverView
.Label
object from the Object Library to `newView.initialView
and drag to popoverView
.Popover
option from the Storyboard Segues
menu that appears.popoverView
and drag to the newView
.Push
option fromt the Storyboard Segues
menu.Click the first button, and the popover appears, but when you click the button within the popover, nothing happens (it should push the new view but doesn't.)
What I want to do is for it to push onto the Navigation Controller
stack, but am not sure how to setup the storyboard for that.
Any ideas?
Under the View menu, select Utilities→Show Object Library. In the Object Library, find the Navigation Controller object (see Figure 4-7) and drag and drop it into the storyboard, to the left side of your existing view controller (Figure 4-6). Now you will see something similar to Figure 4-8.
To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.
Right-click the control or object in your current view controller. Drag the cursor to the view controller you want to present. Select the kind of segue you want from the list that Xcode provides.
You're expecting the UINavigationController
hierarchy to extend itself into a presented popover. It won't. The same goes for presenting modal view controllers. If you were to log self.navigationController
in popoverView
, you would see that it is nil.
Embed popoverView
into it's own UINavigationController
. Remember that if you're overriding prepareForSegue:sender:
and attempting to configure the popover, you will need to get the topViewController
from destinationViewController
as the destination is now an instance of UINavigationController
.
Sounds like it should work, but if it doesn't try the following: 1. Click the segue that doesn't work and give it an identifier. Let's say it's PopoverToNewSegue.
In your implementation file for the popover view controller, add an action when the button is clicked.
That function should return void and add the following line: [self performSegueWithIdentifier:@"PopoverToNewSegue" sender:self];
That should get your segue running. I've noticed that segues don't always work like you expect them to, but this one works for me without fail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With