How to add a UINavigationController to a view in code?

view1 = [[View1 alloc] init]; //Create the first view UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:view1]; navigationController1.navigationBar.tintColor =[UIColor blackColor]; 

View1 inherits from UIViewController. So I create * view1, then create a UINavigationController, call * navigationController1. How to tie them together? Many thanks

+4
source share
3 answers

The answer to this question can be found here: Problem with pushViewController! Help

0
source

A way to associate a view controller with a navigation controller is to push the view controller onto the navigation stack. For instance:

 UIViewController * yourViewController = [[UIViewController alloc] init]; UINavigationController * navigation = [[UINavigationController alloc] init]; [navigation pushViewController:yourViewController animated:NO]; [yourViewController release] 

Finally, release the view controller at the end, as the navigation controller saves it.

+10
source

You may have slightly confused things. A UINavigationController is usually attached to a UIViewController , which is what the UIView contains.

Before writing your own code, you can take a look at the application project of the sample navigation controller, which is available from the list of templates for new Xcode projects to find out how it works.

0
source

Source: https://habr.com/ru/post/1301535/


All Articles