What's purpose of embedding in Navigation Controller?
Asked Answered
D

2

6

I have been recently learning iOS development and a friend tells me that it's good practice to embed views in Navigation Controllers. Is that true and if so why?

What does embedding a View Controller in a Navigation Controller change versus just leaving a View Controller alone?

Dried answered 23/10, 2014 at 2:32 Comment(2)
Take a look at the documentation, it's a good way to start: Anatomy of a Navigation InterfaceCeratodus
Navigation controller is the one of the core feature in iOS, first understand that.Reclamation
M
4

… it's good practice to embed views in Navigation Controllers. Is that true and if so why?

It depends on what you're looking for. Embedding your main view in a view controller gives you some benefits.

  1. It provides an easy way to present and dismiss child view controllers that is very familiar to users.
  2. The navigation bar built into the navigation controller provides good structure: it gives you a place for a title and a tab bar for action buttons.
  3. It handles status bar spacing for you: this can be a pain for apps which still support iOS 6.

What does embedding a View Controller in a Navigation Controller change versus just leaving a View Controller alone?

  1. The navigation controller provides your app with the navigation bar.
  2. The navigation controller provides an easy way to show new view controllers (push) which has a built in UI for users to dismiss the view (back button).
Montoya answered 23/10, 2014 at 2:49 Comment(0)
D
0

A navigation controller allows you to push or pop view controllers. Without this you can't present new views to the user.

Debora answered 23/10, 2014 at 2:34 Comment(2)
You can present new view controllers without a navigation controller, a navigation controller just makes it easier to navigate back through the controller "stack". Not all apps lend themselves to the navigation controller approach, but many doEdward
Fair. The practicality of keeping a navigation controller is, in my opinion, too worthwhile unless you're doing some funky (yet possibly interesting and useful) view management yourself.Debora

© 2022 - 2024 — McMap. All rights reserved.