Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adaptive segue in storyboard Xcode 6. Is push deprecated?

Yes, use ‘Show’ instead of ‘Push’

How can I make "show" work like push? Is it possible or should I use "push (depricated)" instead?

It should; it does for me. I am using Xcode 6 beta 2 and to test I used the single view template (calling the pre made view controller in IB ‘VC_A’). I then added another view controller (‘VC_B’). I then added a button on VC_A to show VC_B and another from VC_B back to VC_A. When I add a navigation controller as the initial view controller in the storyboard and make VC_A the rootViewController, both ‘push’ and ‘show’ have the same effect. If I don’t have an initial navigation controller and I use ‘show’ I get what you described in that the VC_B does a slide up from bottom. If I try to ‘push’ I get a crash since in order to do push I must have navigation controller. So it would seem that ‘show’ will do a push in the case where a navigation controller is provided and do a present with a modal transition style if a navigation controller is not present.

Where can I find any information about new types of segue?

So I found some information in the ‘What’s New in Interface Builder’ session here. If you look at the slides you will see one slide (41) mention the change. When watching that session video you can skip to minute 38:00 where they start talking about adaptive segues. They do explain that the ‘show’ adaptive segue, for example, takes the context in account when deciding how to do the presentation of a new view controller.


There is already an accepted answer, but I wanted to give a bit more information, possibly information that was not available before.

As was mentioned previously, the "push" and "modal" segues were deprecated, and have been replaced by "show" and "present modally" respectively. According to Apple's documentation, the new segues have been further divided into segues that adapt to size classes. The older ones should only be used to support iOS versions older than iOS 8.

The document in the following link explains that and the description of all the available segues, old and new.

Adding a Segue Between Scenes in a Storyboard

In case the URL changes in the future, this is the explanation given for each new segue:

Show

Present the content in the detail or master area depending on the content of the screen. If the app is displaying a master and detail view, the content is pushed onto the detail area. If the app is only displaying the master or the detail, the content is pushed on top of the current view controller stack.

Show Detail

Present the content in the detail area. If the app is displaying a master and detail view, the new content replaces the current detail. If the app is only displaying the master or the detail, the content replaces the top of the current view controller stack.

Present Modally

Present the content modally. There are options to choose a presentation style (UIModalPresentationStyle) and a transition style (UIModalTransitionStyle).

Present as Popover

Present the content as a popover anchored to an existing view. There is an option to specify the possible directions of the arrow shown on one edge of the popover view (UIPopoverArrowDirection). There is also an option to specify the anchor view.


tldr; Delete the Segue that is not pushing correctly and recreate it in the storyboard by dragging from a UIView/UIControl to the target view controller.

There is nothing wrong with the other answers but this one explains what is happening, how you can verify that it is happening and how to mitigate the issue in the future.

Background

In my case, none of my Show Segues were working even though I already had a UINavigationController as my initial view controller (with my content UIViewController as it's root).

Why and How the Show Segue Breaks

The Show segue breaks when it has an action associated with the segue within the storyboard's source xml. A typical scenario causing this might be if you have redefined a segue from a manual segue previously called in code. This leaves the following bits in the storyboard xml.

<connections>
    <segue destination="85t-Z1-hxf" kind="show" identifier="ToOptions" action="showDetailViewController:sender:" id="gdZ-IX-KcN">
</connections>

Nota Bene To view storyboard as xml; Right click the storyboard file and choose Open as > Source Code. To revert use Open as > Interface Builder - Storyboard

To accommodate any custom actions when using the segue from the storyboard one can just tap into prepareForSegue and intercept the destination view controller and call any methods from that location. In any case, the side effect for this little bug (the bug is the fact that when you redefine the segue it is not properly setup in xml ~ i.e. the action remains even after your change the segue to one that operates from a UIView (or UIControl) to a target view controller).

Unfortunately the most direct solution fails. So just removing the xml attribute for the action from within the Storyboard will NOT fix the problem. Instead one has to simply delete and recreate the segue in the storyboard.

When recreated the storyboard xml will no longer have an action associated with the particular segue and the Show will execute as a Push.

Sample Xml for correct Show Segue

  <connections>
    <segue destination="RbV-Au-WV9" kind="show" identifier="ToOptions" id="5dm-os-bcS"/>
  </connections>

Mitigation

To prevent recurrence one just needs to stick to non-manual storyboard segues if possible by using the prepareForSegue to add required actions based on destination view controller. Or if you must to mix and match, take the precaution to verify that your Show segues do not have any actions attached in the storyboard xml. If you are dealing with older projects then you should give special attention to the Storyboard source code as I've discovered a few issues.


As Scott Robertson commented here, this looks like a bug in iOS 7.

It appears that in iOS 8 the transition is inferred at runtime (correct behavior), while in iOS 7 the transition is inferred at design time (buggy behavior).

The simplest workaround is to add an unused navigation controller to the storyboard and link it up so that the view controller in question is part of this navigation controller. You don't actually have to instantiate the navigation controller, you just need the buggy view controller to know it is embedded in a navigation controller.

Note: Simulating a navigation bar is not sufficient for these purposes; you must actually have a navigation controller in its push stack.

To reproduce the bug:

  1. Create a new storyboard that uses size classes.
  2. Create a two view controllers (no navigation controllers).
  3. Make the first view controller show the second view controller via a Show (e.g. Push) segue linked to a button, for example.
  4. In code, show the first view controller, but embed it in a navigation controller via the initWithRootViewController: method.
  5. Run the app on iOS 7.
  6. Tap the button that should perform the push.
  7. You will get a modal transition instead of a push on iOS 7. On iOS 8 you will get the correct, push behavior.

enter image description here

To fix the bug:

  1. Add a navigation controller to the storyboard and set the first view controller to be the root view controller. (Note: adding the second as the root view controller will NOT fix this bug.)
  2. Give it a junk identifier to suppress the warning about the navigation controller being inaccessible, and to document to yourself that it exists solely as a workaround. (e.g. workaround for show segues in iOS 7).

enter image description here

Notice how the navigation controller was added in the second picture, and how it doesn't have any incoming arrows (i.e. there is no way to instantiate it other than using its view controller identifier).