简体   繁体   中英

IOS/Storyboard: When is it really necessary to embed a view controller in a navigation controller

I have a project with a number of view controllers. Because I sometimes needed to put a Done in the nav bar or the View Controllers launched modally and needed a cancel button in the nav bar, I got in the habit of embedding my view controllers in Navigation Bars.

However, when building the App, I noticed that I get a lot of warnings about Navigation Controllers being:

unreachable because it has no entry points, and no identifier for runtime access via -[UIStoryboard instantiateViewControllerWithIdentifier:].

So far, I've discovered that in these cases there is normally a segue from another view controller directly to the view controller in question. And usually there are no Done buttons or other bar button items in the VC.

Upon deleting some of these "unreachable" navigation controllers, I've noticed that it doesn't seem to affect anything. The VCs still have a back button in them and function identically. It seems that the compiler automatically places a nav bar in these VCs with a back button and they behave the same as if they were embedded in the nav controller.

My immediate question is am I safe deleting these unreachable NavBar Controllers. My broader question is: Is there a rule or principle for when you should embed the VC in a Nav, for example, when you want to insert bar buttons other than Back, and when you do not need to use a Nav.

Thanks for any suggestions.

In short, navigation controller allows developer to manager views without typing out too many codes. for example

with navigation controller you can do

navigationController?.pushViewController(yourViewController, animated: true) or

navigationController?.popViewController(animated: true)

without implement navController you can only do

present(yourViewController, animated: true, completion: nil) or

self.dismiss(animated: true, completion: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM