Document directory
- 1. Important uinavigationcontroller Parameters
- 2. Create uinavigationcontroller
- 3. Full Screen uinavigationcontroller
- 4. Adjust the content of navigation and related event streams
- 5. display the navigation Toolbar
- 6. common methods and parameters
- References
- Reference Code
1. Important uinavigationcontroller Parameters
2. Create uinavigationcontroller
UIViewController *myViewController = [[MyViewController alloc] init]; navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController]; window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; window.rootViewController = navigationController; [window makeKeyAndVisible];
Or use nib to create
3. Full Screen uinavigationcontroller
1. navigation bar: Set the translucent of navigationcontroller to yes.
2. toolbar: Set the translucent of the toolbar to yes.
3. Set wantsfullscreenlayout to yes.
Nav. navigationbar. translucent = yes; // The navigation bar can be a content area with transparent nav. toolbarhidden = no; // display the built-in toolbar nav. toolbar. translucent = yes; // The toolbar can be a content area and transparent
4. Adjust the content of navigation and related event streams
Adjust viewcontrollers
A) pushviewcontroller: animated:
B) popviewcontrolleranimated:
C) setviewcontrollers: animated:
D) poptorootviewcontrolleranimated:
E) poptoviewcontroller: animated:
F) You can also directly set viewcontrollers. The displayed view will be the lastobject of array.
Monitoring event
In addition to the general controller overwrite method, you can also use delegate to track the status.
5. Define the navigation bar style
1. Similar to the viewcontrollers structure of the navigation controller, the navigation bar is data that contains the uinavigationitem type.
The arrays of each viewcontrollers and navigationitem are parallel to each other. For example, the location of a controller in viewcontrollers is the same as that in items.
Viewcontroller obtains the corresponding item through the navigationitem parameter.
The main parameters and positions of navigationitem are as follows:
Left: backbarbuttonitem, which is added by default in navigation Controller
Leftbarbuttonitem: This is the uibarbuttonitem of custom.
Right: rightbarbuttonitem: Same as the custom uibarbuttonitem
Middle: titleview: Use your custom view to display the middle part as the title. If you do not use the view settings, use the string object title.
For details, see:
2. uinavigationbar Parameter
A) barstyle: bar style
B) Translucent: whether it is transparent. The content is displayed in the navigationbar.
C) tintcolor: Background Color
3. Set the default editbutton of viewcontroller in navigationbar
myViewController.navigationItem.rightBarButtonItem = [myViewController editButtonItem];
5. display the navigation Toolbar
1. toolbar Structure
Each content View Controller has an array of corresponding toolbaritems. Instances of the toolbaritem class are stored in the array.
UIBarButtonItem *flexibleSpaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; // Create and configure the segmented control UISegmentedControl *sortToggle = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Ascending", @"Descending", nil]]; sortToggle.segmentedControlStyle = UISegmentedControlStyleBar; sortToggle.selectedSegmentIndex = 0; [sortToggle addTarget:self action:@selector(toggleSorting:) forControlEvents:UIControlEventValueChanged]; // Create the bar button item for the segmented control UIBarButtonItem *sortToggleButtonItem = [[UIBarButtonItem alloc] initWithCustomView:sortToggle]; // Set our toolbar items self.toolbarItems = [NSArray arrayWithObjects: flexibleSpaceButtonItem, sortToggleButtonItem, flexibleSpaceButtonItem, nil];
6. common methods and parameters
Uiviewcontroller:
-(Void) hidesbottombarwhenpushed: automatically hides the toolbar at the bottom when pushing or pop from the navigation stack.
References
View Controller catalog for iOS
Reference Code
(Apple official) navbar