1 , Overview:
With Uinavigationcontroller, you can easily manage multiple controllers and easily switch between controllers, typically in the "settings" app that comes with your system.
2 , Uinavigationcontroller the simple use
Uinavigationcontroller the use steps :
Complete the following in the Mjappdelegate Didfinishlaunchingwithoptions method:
(1) Initialize Uinavigationcontroller
Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] init];
(2) Set UIWindow Rootviewcontroller to Uinavigationcontroller
Self.window.rootViewController = nav;
(3) Depending on the situation, add the corresponding number of sub-controllers by the push method
Uiviewcontroller *VC1 = [[Uiviewcontroller alloc] init];
Vc1.view.backgroundColor = [Uicolor redcolor];
[Nav pushviewcontroller:vc1 Animated:yes];
Uiviewcontroller *VC2 = [[Uiviewcontroller alloc] init];
Vc2.view.backgroundColor = [Uicolor greencolor];
[Nav PUSHVIEWCONTROLLER:VC2 Animated:yes];
Operating effect:
In the actual development often is to add a viewcontroller to Uinavigationcontroller, click on the button to jump to the next viewcontroller. Click the button to jump to the next Viewcontroller code:
Twoviewcontroller *two = [[Twoviewcontroller alloc] init];
[Self.navigationcontroller Pushviewcontroller: Animated:yes];
After jumping to the next viewcontroller the top navigation bar will automatically appear back button, click to return to the original interface.
3 , Uinavigationcontroller the child controller
Uinavigationcontroller Saves the sub-controller as a stack, and when the Uinavigationcontroller is initialized, it can be Initwithrootviewcontroller by : method to pass in a controller as the root controller, the root controller is always on the bottom of the stack (if there is only one object in the stack, the root controller is also on top of the stack).
@property (nonatomic,copy) Nsarray *viewcontrollers;
@property (nonatomic,readonly) Nsarray *childviewcontrollers;
Use Push method can push a controller into the stack:
-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated:
(BOOL) animated;
In summary, there are three ways to add a sub-controller to a navigation controller:
(1) [Nav Addchildviewcontroller:myviewcontroller];
(2) [Nav Pushviewcontroller:myviewcontroller Animated:yes];
(3) Nav.viewcontrollers = @[Myviewcontroller];
You can also add a sub-controller directly when you initialize the navigation controller:
Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] initwithrootviewcontroller:myviewcontroller];
Use Pop methods to remove the controller:
Remove the controller from the top of the stack :
-(Uiviewcontroller *) popviewcontrolleranimated: (BOOL) animated;
Back to the specified child controller:
-(Nsarray *) popto Viewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
Back to the root controller (stack bottom controller):
-(Nsarray *) poptorootviewcontrolleranimated: (BOOL) animated;
iOS Development Uinavigationcontroller