Difference between navigation controller and viewcontroller?

拥有回忆 提交于 2019-12-23 19:51:54

问题


Difference between navigation controller and viewcontroller? I mean how can we decide when to use navigation controller or a normal view controller?


回答1:


Just my two cents:

A UIViewController represents a single view and you can put buttons in this view controller to segue to another UIViewController. If you want to segue back to the first UIViewController, you will have to worry about putting a button in the second view controller that leads back to the first. If you are drilling down into view controllers, this can be tedious having to remember to give the user a way back to a previous view controller.

A UINavigationController does a lot of this tedious work for you. As mentioned, it contains a stack of UIViewControllers. It will create a navigation bar at the top that will allow you to easily go back up the hierarchy of view controllers.

In short, if you have a hierarchy of view controllers that you want the user to easily navigate around, inbed your UIViewControllers into a UINavigation controller.




回答2:


Here's a very brief, high-level overview.

Whereas a UIViewController can be thought of as representing a single 'screen', UINavigationController, as the name implies, is used as a means of being able to navigate multiple 'screens'.

From the documentation:

The UINavigationController class implements a specialized view controller that manages the navigation of hierarchical content. This navigation interface makes it possible to present your data efficiently and makes it easier for the user to navigate that content. You generally use this class as-is but in iOS 6 and later you may subclass to customize the class behavior.

Please see the rest of the UINavigationController documentation here: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UINavigationController_Class/index.html




回答3:


See the Navigation Controller discussion in the View Controller Catalog.

Bottom line, a navigation controller actually is a view controller, but it just happens to be one that presents and navigates between other view controllers.




回答4:


Okay, Thank you everyone for helping me to find out a clear answer on this.

Navigation Controller consists of navigation bar and tool bar to move in and out from view controllers present in navigation stack.Therefore there can be many view controllers in Navigation Controller.

In view controller we don't have this facility and it represents a single screen view.

Please correct me If I am wrong.




回答5:


  1. UINavigation Controller is a combination of 2 or more view controllers,those are connected through "segue" feature of "Ios". Benefit of using Navigation Controller is that we can navigate between different screens easily with default "Back" button on each screen . We don't need to give any individual button to move back onto previous screen. Whereas a ViewController provides a single screen & we can connect more screen using "segue" but we also have to design a "Back" button to navigate onto previous screen.

  2. We should use Navigation Controller , in case where one option resides into another one.Like in an iPhone settings ->Mobile Data Options->Voice->4G or 3G or 2G. It's a hierarchy of menus so here navigation Controller is better option than using UIController. We should use UiController with "segue " , in case where we have to choose one option among multiple.Like - Photos ->There are many folders in which , any one is selected, that are Favourites or People or Places .



来源:https://stackoverflow.com/questions/28751457/difference-between-navigation-controller-and-viewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!