Navigation Controller-UI Navigation Controller
In the development of multi-controller, the first bound is a controller. Navigation controller can easily complete the switch between controllers.
View structure of navigation controller.
Navigation Controller It's a controller. It must have a View.
The navigation controller logo is the last one. This one, we call it the navigation bar. This navigation bar is displayed on the navigation controller View.
The Y value of the navigation bar is 20, and the top 20 is the 2 position of the status bar. The degree of the navigation bar is 44. (UINavigation Bar)
The Y value of the navigation bar is 20 and the degree is 44, but the navigation bar we see has a translucent effect. It starts from zero position. It is actually a control inside the navigation bar. It exceeds the degree of the navigation bar, and the control can be displayed when it exceeds the control.
UINavigation Controller uses
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc]; // The initWithRootViewController method uses the bottom tuning push method. [nav pushViewController:vc animated:YES];
- push
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated;
Navigation controllers are added to navigation controllers by push method. Navigation controllers add views of sub-controllers to views of navigation controllers which are stored exclusively in sub-controllers. Navigation controller initWithRoot View Contorllers: Setting the root controller of navigation controllers. In fact, the bottom adjustment is the push method of navigation controllers to control the transmission. Controller, added as the controller of navigation controller.
Note: The navigation controller must have a root controller.
There is an array of childsViewControllers in the navigation controller, in which all the controllers of the navigation controller are stored.
Each controller can get its current navigation controller, because the current controller is a sub-controller of the navigation controller.
- pop
//Return to the previous level //PoViewController removes the current controller from the navigation controller. [self.navigationController popViewControllerAnimated:YES]; //Return to the root controller of the navigation controller [self.navigationController popToRootViewControllerAnimated:YES]; //Return to the specified controller //The popToViewController must be a sub-controller of the current navigation controller. //self.navigationController.childViewControllers [self.navigationController popToViewController:Designated viewcontroller animated:YES];
NavigationItem
The content of navigation bar is determined by the navigationItem model of the controller.
Common settings for navigation bars
//Setting titles self.navigationItem.title = @"Title"; //Set the title to a UIView control self.navigationItem.titleView = [UIButton buttonWithType:UIButtonTypeContactAdd]; //Set the left button of the navigation bar //style sets all attributes from ios7. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Return" style:0 target:self action:@selector(back)]; //Note: // Manual implementation of the left button, the system return function, will fail. //Setting Pictures //Note: By default, the navigation bar will automatically render its image blue. UIImage *image = [UIImage imageNamed:@"navigationbar_friendsearch"]; image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; //self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:0 target:self action:@selector(rightClick)]; UIButton *btn = [[UIButton alloc] init]; [btn setImage:[UIImage imageNamed:@"navigationbar_friendsearch"] forState:UIControlStateNormal]; [btn setImage:[UIImage imageNamed:@"navigationbar_friendsearch_highlighted"] forState:UIControlStateHighlighted]; //Let the size of the button adjust. [btn sizeToFit]; //To customize UIView, you must set the size. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];