0

If I have the storyboard in the form of (where the arrows are segues)

UINavigationController -> ViewControllerA -> ViewControllerB

Would that be basically more or less equivalent to

ViewControllerA -> ViewControllerB
(NavigationBar)    (NavigationBar)

if I manually wire each NavigationBar up to Button Bar Items with event listeners attached to unwind segues?

Or does UINavigationController offer something more than that?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
AlanSTACK
  • 5,525
  • 3
  • 40
  • 99
  • I don't see why you would do that? Also using a `UINavigationController ` allows you to do things like pop to a certain ViewController. In the other escenario you would need to do more hacks to get that behavior. – Enrique Bermúdez Feb 21 '18 at 19:19
  • @EnriqueBermúdez I am learning and curious. Could you please elaborate more on your example please? I would be more than happy to accept it as an answer should you go into more detail about it. – AlanSTACK Feb 21 '18 at 19:22

3 Answers3

1

There are some differences.

One that I have noticed, a UINavigationController will handle correctly putting the navigation bar in the right place for iPhone X vs other models (It will make the height larger so it goes into the wedge of the of screen, while just a nav bar will remain its standard height).

If you just put a nav bar on each UIViewController, you are going to have to check on each view controller if you need to update the bar size.

Jake G
  • 1,185
  • 9
  • 19
1

Basically the navigationController provides you many thing that you might use: A stack of UIViewControllers, a navigation bar, a toolbar, delegate methods, show/pop animations, etc. Doing all that by hand will be not too appropriate and a little bit messy. I suggest you to take a look to the Apple’s documentation for UINavigationController. There you will get a much better understanding of all the capabilities and methods that this class provides you.

Enrique Bermúdez
  • 1,740
  • 2
  • 11
  • 25
1

UINavigationController is what is known as a container view-controller: it takes a bunch of other view-controllers and manages how their views are presented on the screen. UISplitViewController is another example of a container view-controller.

In the case of UINC, it:

  • Allows pushing a new "top" controller, animating it with a left-to-right/right-to-left animation depending on locale
  • Remembers the stack of previous top controllers, allowing you to pop back to them
  • Adds a UINavigationBar view above the top controller's view so the user can pop back by themselves (you can disable this)
  • Sets a layoutMargin on the top controller's view, so it can adjust content to not underlap the bar
  • Provides an edge-swipe gesture so the user can interactively pop to previous controllers (slowly peel the top sheet back)

For more information, including about how to create your own container view-controllers, see Apple's documentation on the subject: https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

karwag
  • 2,641
  • 1
  • 15
  • 12
  • Thank you for your response. But could I just manually add a `NavigationBar` to each scene and use unwind segues to achieve similar effects? I am largely stuck on the part `Remembers the stack of previous top controllers, allowing you to pop back to them`. Isn't this already inherent even without a `UINavigationController`? – AlanSTACK Feb 22 '18 at 02:01
  • 1st q: There is a kind of view-controller hierarchy (in parallel with the view hierarchy), but it isn't for what you expect. The controller hierarchy tells you things like that a UINC is the "parent" of the controllers in its pages. The pages themselves have a sibling relationship in the controller hierarchy (but not the navigation stack). 2nd q: yes, you certainly could create a kind of poor-man's navigation controller with a bunch of static screens. UINC can be controlled dynamically though, with code, and contains lots of built-in behaviours and transitions. It's best to use it. – karwag Mar 01 '18 at 19:02
  • Thank you for your response. Just to make sure I have it right, when you say `yes, you certainly could create a kind of poor-man's navigation controller with a bunch of static screens.` Does that mean all built-in behaviour such as state restoration would also automatically preserve this "poor man's scene hierarchy"? – AlanSTACK Mar 01 '18 at 19:07
  • State restoration will work, I think. Basically, view controllers also have this ability to "present" a full-screen modal view-controller. Those controllers can present another controller, etc. So you kind of build a stack of controllers that way. So anything that works with `presentViewController` should work. You might also want to check out this post (which, by some massive coincidence, also uses the term 'poor-man's navigation controller'): https://stackoverflow.com/a/14233252/1151216 – karwag Mar 01 '18 at 19:14
  • Thank's I really appreciate your help – AlanSTACK Mar 01 '18 at 19:15