Difference between pushViewController and showViewController

前端 未结 2 1298
夕颜
夕颜 2021-02-18 12:35

What\'s the difference between pushViewController and showViewController methods on UINavigationController?

相关标签:
2条回答
  • 2021-02-18 13:23

    You use this method to decouple the need to display a view controller from the process of actually presenting that view controller onscreen.

    Using this method, a view controller does not need to know whether it is embedded inside a navigation controller or split-view controller. It calls the same method for both. The UISplitViewController and UINavigationController classes override this method and handle the presentation according to their design. For example, a navigation controller overrides this method and uses it to push vc onto its navigation stack.

    form Apple UIKit Documentation

    0 讨论(0)
  • 2021-02-18 13:32

    Show segue can be used with navigation controllers, they simply push viewControllers on your stack.

    Show detail segue has only sense with split view controllers. Since you have two viewControllers inside your split view controller you can:

    navigate in your master view controller by presenting (pushing, since the default project uses a navigationVC as master VC) view controllers with Show segue show details in your detail view controller with Show detail segue In case you don't know how a Split view controller is composed:

    **************++++++++++++++++++
    *            *                 +
    *            *                 +
    *   master   *      detail     +
    *    view    *       view      +
    * controller *    controller   +
    *            *                 +
    *            *                 +
    **************++++++++++++++++++
    

    BUT !

    On iphones it's presented like this (iPhone6+ landscape excluded)

    ****************
    *++++++++++++++*
    *+            +*
    *+            +*
    *+            +*
    *+   detail   +*
    *+    view    +*
    *+ controller +*
    *+            +*
    *+            +*
    *++++++++++++++*
    ****************
    

    Both of Showsegue and Show detail segue are new to iOS8 & Xcode6, they are called adaptative segues, they behaves differently depending on the device type or the orientation.

    Basically, Show segue and Show detail segue seems to do the same thing on iPhones, since there is no much space to present view controllers side by side.

    Technically, you don't present details several times until you go back in your navigation. Only the master view controller should perform Show detail segues, a detail view controller should be a leaf in your navigation tree (but it's not forbidden to use a navigationVC as a leaf ;) )

    Hope it helps.

    0 讨论(0)
提交回复
热议问题