Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between pushViewController and showViewController

Tags:

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

like image 620
tailec Avatar asked Feb 13 '15 11:02

tailec


People also ask

What is present Modally?

Present Modally - Presents a view controller overtop the current view controller in various fashions as defined by the modal presentation and transition style - most commonly used to present a view controller in a sheet that animates up from the bottom. Example: Selecting Face ID & Passcode in Settings.

What is UIViewController in IOS?

The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.


2 Answers

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.

like image 109
Aadil Keshwani Avatar answered Sep 30 '22 18:09

Aadil Keshwani


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

like image 27
Hashem Aboonajmi Avatar answered Sep 30 '22 19:09

Hashem Aboonajmi