Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In an iOS 5 Storyboard, how do you push a new scene to the original view controller from a Popover?

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:

  1. Create a new Single View Application
  2. Select Use Storyboards
  3. Select the MainStoryboard.storyboard file.
  4. Select the only View Controller, change the Title and Identifier to initialView, then select Editor->Embed In->Navigation Controller
  5. Drag two new View Controller objects from the Objects Library onto the canvas
  6. Change the Title and Identifier of the new View Controllers to: popoverView and newView.
  7. Add a Round Rect Button object from the Object Library to initialView and popoverView.
  8. Add a Label object from the Object Library to `newView.
  9. Control click the button in the initialView and drag to popoverView.
  10. Select the Popover option from the Storyboard Segues menu that appears.
  11. Control click the button in the popoverView and drag to the newView.
  12. Select the Push option fromt the Storyboard Segues menu.
  13. Build & Run.

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?

like image 684
lnafziger Avatar asked Oct 16 '11 19:10

lnafziger


People also ask

How do I add a view controller scene in storyboard?

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.

How do I segue between view controllers?

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.

How do I change the view in Xcode?

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.


2 Answers

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.

like image 90
Mark Adams Avatar answered Nov 14 '22 01:11

Mark Adams


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.

  1. In your implementation file for the popover view controller, add an action when the button is clicked.

  2. 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.

like image 24
UntitledNo4 Avatar answered Nov 14 '22 02:11

UntitledNo4