Difference between pushViewController and showViewController

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

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

2条回答
  •  灰色年华
    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.

提交回复
热议问题