IOS Development View Switch _ios

Source: Internet
Author: User

One, view switch

    1. Uitabbarcontroller (Paging Controller)-Parallel management view
    2. Uinavigationcontroller (navigation Controller)-pressure stack out stack management view
    3. Modal window

Second, Uitabbarcontroller paging controller

    1. Uitabbarcontroller is designed to take advantage of the page Check switch view design controller
    2. The controller has a Uitabbar control and the user clicks Uitabbar to toggle the view
    3. Uitabbarcontroller itself will not display any views, it is just a container controller
    4. In order to reduce the coupling between views, all uitabbarcontroller of the child view of the relevant title, icon, etc.

Precautions:

    1. Uitabbarcontroller initializes all of the child controllers at once, but only the first controller view is loaded by default
    2. Each view controller has a Tabbarcontroller property that is used to access the Uitabbarcontroller
    3. Each view controller has a Tabbaritem property that controls the display information on the Uitabbarcontroller Uitabbar
    4. The Image property of the Tarbaritem must be in PNG format and the alpha channel is open, otherwise it will not display correctly
    5. 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:

    1. Create a Uitabbarcontroller object
    2. Create an object to display for each tab in the Uitabbarcontroller Viewcontroller
    3. Add all Viewcontroller that will be displayed through the Uitabbarcontroller Viewcontrollers property to Uitabbarcontroller
    4. 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

    1. Change the SelectedIndex property
    2. Change the Selectedviewcontroller property
    3. Change the Viewcontrollers property

Three, Uinavigationcontroller navigation controller

    1. 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
    2. Pressure stack Pushcontroller, out stack Popcontroller
    3. Uinavigationcontroller must have a root controller Rootviewcontroller
    4. The child controller accesses the Uinavigationcontroller through the Navigationcontroller property
    5. 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:

    1. Navigation Bar Returns the caption of the button Backbarbuttonitem
    2. Title of navigation bar Navigationitem
    3. 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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.