IOS uses code and storyboard to create Uitabbarcontroller separately

Source: Internet
Author: User

Transferred from http://blog.csdn.net/ssrrxx111/article/details/48315843

1, the most common one of iOS layout, at the bottom of the tab navigation, control the different views.


2, the use of code to create Uitabbarcontroller.

1) in the Appdelegate

[HTML] view plain copy print? -(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) LaunchOptions method, Create a new Uitabbarcontroller, and then create a new Uiviewcontroller or uitableviewcontroller that you want. Use these views as the root view of the Uinavigationcontroller. Use Method Initwithrootviewcontroller.

2 Set the Uitabbarcontroller Viewcontrollers property, here is an array, you can set the previous Uinavigationcontroller in the array.

3) Gets the Tabbar property of the Uitabbarcontroller. Then create multiple uitabbaritem corresponding to the above view. Sets the title and image of the Uitabbaritem, corresponding to the headings and images respectively.

In the Tabbarcontroller can only put 4 tab, if more than 4, then will automatically generate a more tab, and then put the Extra tab in the more corresponding Tableviewcontroller view.

The code to create Uitabbarcontroller using code is as follows:

[OBJC]  View plain  copy  print? -  (BOOL) Application: (uiapplication *) Application didfinishlaunchingwithoptions: (NSDictionary  *) launchoptions {       // Override point for  customization after application launch.               MainController *mainController = [[MainController alloc] init];        BaseNavigationController *mainNavCtl = [self  initlizernavigationcontrollerwithrootviewcontroller:maincontroller];               maincontroller *maincontroller2 = [[maincontroller alloc]  init];       basenavigationcontroller *mainnavctl2 = [self  initlizerNavigationControllerWithRootViewController:mainController2];    &NBsp;         maincontroller *maincontroller3 = [[ maincontroller alloc] init];       basenavigationcontroller * mainnavctl3 = [self initlizernavigationcontrollerwithrootviewcontroller:maincontroller3];               maincontroller *maincontroller4 =  [[MainController alloc] init];       basenavigationcontroller  *MAINNAVCTL4 = [SELF INITLIZERNAVIGATIONCONTROLLERWITHROOTVIEWCONTROLLER:MAINCONTROLLER4] ;                 //settings Bottom tabbar       UITabBarController *tab = [[UITabBarController alloc] init];        TAB.VIEWCONTROLLERS = @[MAINNAVCTL,MAINNAVCTL2,MAINNAVCTL3, mainnavctl4];              UITabBar *tabBar = tab.tabBar;               uitabbaritem *tabbaritem1 =  [tabBar.items objectAtIndex:0];       uitabbaritem *tabbaritem2  = [tabBar.items objectAtIndex:1];       uitabbaritem * tabbaritem3 = [tabbar.items objectatindex:2];       uitabbaritem  *tabBarItem4 = [tabBar.items objectAtIndex:3];  

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.