One, view switch
- Uitabbarcontroller (Paging Controller)-Parallel management view
- Uinavigationcontroller (navigation Controller)-pressure stack out stack management view
- Modal window
Second, Uitabbarcontroller paging controller
- Uitabbarcontroller is designed to take advantage of the page Check switch view design controller
- The controller has a Uitabbar control and the user clicks Uitabbar to toggle the view
- Uitabbarcontroller itself will not display any views, it is just a container controller
- In order to reduce the coupling between views, all uitabbarcontroller of the child view of the relevant title, icon, etc.
Precautions:
- Uitabbarcontroller initializes all of the child controllers at once, but only the first controller view is loaded by default
- Each view controller has a Tabbarcontroller property that is used to access the Uitabbarcontroller
- Each view controller has a Tabbaritem property that controls the display information on the Uitabbarcontroller Uitabbar
- The Image property of the Tarbaritem must be in PNG format and the alpha channel is open, otherwise it will not display correctly
- Uitabbarcontroller is usually the rootviewcontroller of the entire program, and we need to create it before the window of the program is displayed.
The specific steps are as follows:
- Create a Uitabbarcontroller object
- Create an object to display for each tab in the Uitabbarcontroller Viewcontroller
- Add all Viewcontroller that will be displayed through the Uitabbarcontroller Viewcontrollers property to Uitabbarcontroller
- By setting the Uitabbarcontroller object to Window.rootviewcontroller, and then displaying the window
Copy Code code as follows:
A. Initializing a Tabbar controller
Uitabbarcontroller *TARBARVC = [[Uitabbarcontroller alloc] init];
Setting the root controller for Windows
Self.window.rootViewController = TARBARVC;
B. Creating a child controller
Uiviewcontroller *C1 = [[Uiviewcontroller alloc] init];
C1.view.backgroundColor = [Uicolor Graycolor];
C1.view.backgroundcolor=[uicolor Greencolor];
C1.tabBarItem.title = @ "message";
C1.tabBarItem.image = [UIImage imagenamed:@ "Tab_recent_nor"];
C1.tabBarItem.badgeValue = @ "123";
Uiviewcontroller *C2 = [[Uiviewcontroller alloc] init];
C2.view.backgroundColor = [Uicolor Browncolor];
C2.tabBarItem.title = @ "Contact";
C2.tabBarItem.image = [UIImage imagenamed:@ "Tab_buddy_nor"];
Uiviewcontroller *c3 = [[Uiviewcontroller alloc] init];
C3.tabBarItem.title = @ "dynamic";
C3.tabBarItem.image = [UIImage imagenamed:@ "Tab_qworld_nor"];
Uiviewcontroller *C4 = [[Uiviewcontroller alloc] init];
C4.tabBarItem.title = @ "Set";
C4.tabBarItem.image = [UIImage imagenamed:@ "Tab_me_nor"];
C. Add a child controller to Itabbarcontroller
Tarbarvc.viewcontrollers = @[c1,c2,c3,c4];
D. Set Windows as the primary window and display it
[Self.window makekeyandvisible];
Uitabbarcontrollerdelegate Agent
Copy Code code as follows:
#pragma mark this method is used to control whether Tabbaritem can be selected
-(BOOL) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Shouldselectviewcontroller: (UIViewController *) Viewcontroller;
Change the way Uitabbarcontroller currently displays views
- Change the SelectedIndex property
- Change the Selectedviewcontroller property
- Change the Viewcontrollers property
Three, Uinavigationcontroller navigation controller
- The Uinavigationcontroller in the stack is stored in the form of stacks, only the controller at the top of the stack can be displayed on the interface
- Pressure stack Pushcontroller, out stack Popcontroller
- Uinavigationcontroller must have a root controller Rootviewcontroller
- The child controller accesses the Uinavigationcontroller through the Navigationcontroller property
- The sub controller in the stack has a navigation bar navigationbar, through Navigationitem to control
Uinavigationitem belongs to model in MVC, encapsulating the data to be displayed on the Uinavigationbar:
Title: Titles
Titleview: Caption View
Leftbarbuttonitem: Left button
Rightbarbuttonitem: Right button
The next child view returns the caption priority of the button Leftbarbuttonitem:
- Navigation Bar Returns the caption of the button Backbarbuttonitem
- Title of navigation bar Navigationitem
- Title of the View controller
The main methods commonly used in Uinavigationcontroller:
Copy Code code as follows:
#pragma Mark Press stack, press the controller into the navigation Controller sub Controller stack
-(void) Pushviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
#pragma mark out the stack, eject the top of the stack of the navigation controller's sub controller
-(void) popviewcontrolleranimated: (BOOL) animated;
#pragma mark several times out of stack until the top of the stack is the specified controller
-(void) Poptoviewcontroller: (Uiviewcontroller *) Viewcontroller animated: (BOOL) animated;
#pragma mark multiple stacks until the top of the stack is the root controller
-(void) poptorootviewcontrolleranimated: (BOOL) animated;
Four, modal window
Copy Code code as follows:
#pragma mark pops up the specified view controller from below, giving the modal that the contents of the other views cannot be manipulated before the current view is closed
-(void) Presentviewcontroller: (Uiviewcontroller *) viewcontrollertopresent animated: (BOOL) flag completion: (void (^) ( void)) completion;
#pragma mark closes the modal window, which is called in the modal window
-(void) dismissviewcontrolleranimated: (BOOL) flag completion: (void (^) (void) completion;