Navigation bar Controller and tab bar Controller (Uinavigationcontroller and Uitabbarcontroller) mix

Source: Internet
Author: User

Most of the time, the use of both the navigation controller and the tab bar controller in UI design requires mastering how the two different controllers are designed to work together. such as mobile phone QQ, the program has three tabs (messages, contacts, dynamic), while selecting a contact or session, will enter the chat sub-page, so the use of both the tab bar controller and navigation controller.

I now know that the following methods can be used to achieve the combined effect of the above.

  • The root view is the tab bar controller, and then each page tab bar has a root view controller as the navigation bar Controller's label, as shown in the following code
    //message messageviewcontroller* msg = [[Messageviewcontroller alloc] init]; uinavigationcontroller* Navcontrololer = [[Uinavigationcontroller alloc] init]; [Navcontrololer pushviewcontroller:msg Animated:yes]; [Viewarray addobject:navcontrololer];//contacts contactviewcontroller* contact = [[Contactviewcontroller alloc] init]; Navcontrololer = [[Uinavigationcontroller alloc] init]; [Navcontrololer pushviewcontroller:contact Animated:yes]; [Viewarray addobject:navcontrololer];//dynamic favoriteviewcontroller* favorite = [[Favoriteviewcontroller alloc] init]; Navcontrololer = [[Uinavigationcontroller alloc] init]; [Navcontrololer Pushviewcontroller:favorite Animated:yes]; [Viewarray addobject:navcontrololer];//tab Bar Controller uitabbarcontroller* tabbarcontroller = [[Uitabbarcontroller alloc] Init ];tabbarcontroller.viewcontrollers = viewarray;//Modify the root view appdelegate* appdelagete = [UIApplication sharedApplication]. Delegate;appdelagete.window.rootviewcontroller = Tabbarcontroller; 
    The above code is in the Viewcontroller.m file, that is, the app's root view controller can be changed in other places outside the Appdelegete, so you can design the login interface before displaying the main page of the program, that is, the tab bar Page view. Note that the root view is the tab bar, so the return button is not valid, as shown below
  • If the root view of the above code is the navigation bar, then the return button is valid and can be used as a similar function for exiting login, the main implementation is as follows, setting the root view controller in Appdelegate
    -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions{    Override point for customization after application launch.    Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];        uinavigationcontroller* Navcontroller = [[Uinavigationcontroller alloc] init];    [Navcontroller Pushviewcontroller:[[viewcontroller alloc] init] animated:yes];        Self.window.rootViewController = Navcontroller;    return YES;}
    Then Viewcontroller push the TAB bar controller as a sub-view of the navigation bar controller, and the code is
    -(void) loginsuccess{//Enter the main interface, change the root view nsmutablearray* Viewarray = [[Nsmutablearray alloc] init]; Navigation Controller + Table tab bar Controller combined,//each tag has a root navigation controller//message messageviewcontroller* msg = [[Messageviewcontroller alloc] Ini    T];    uinavigationcontroller* Navcontrololer = [[Uinavigationcontroller alloc] init];    [Navcontrololer pushviewcontroller:msg Animated:yes];        [Viewarray Addobject:navcontrololer];    Contact contactviewcontroller* contacts = [[Contactviewcontroller alloc] init];    Navcontrololer = [[Uinavigationcontroller alloc] init];    [Navcontrololer pushviewcontroller:contact Animated:yes];        [Viewarray Addobject:navcontrololer];    Dynamic favoriteviewcontroller* favorite = [[Favoriteviewcontroller alloc] init];    Navcontrololer = [[Uinavigationcontroller alloc] init];    [Navcontrololer Pushviewcontroller:favorite Animated:yes];        [Viewarray Addobject:navcontrololer]; TAB BAR Controller uitabbarcontroller* tabbarcontroller = [[Uitabbarcontroller alLOC] init];   Tabbarcontroller.viewcontrollers = Viewarray;    #ifdef Tabroot//Modify the root view for the tab bar Controller appdelegate* appdelagete = [UIApplication sharedapplication].delegate; AppDelagete.window.rootViewController = Tabbarcontroller; #else//Push the TAB bar view controller to the navigation bar Controller [Self.navigationcontroller p Ushviewcontroller:tabbarcontroller Animated:yes]; #endif}
    The effect is as follows

Navigation bar Controller and tab bar Controller (Uinavigationcontroller and Uitabbarcontroller) mix

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.