Uitabbarcontroller in iOS (Tag view controller)

Source: Internet
Author: User

#import"AppDelegate.h"#import"FirstTableViewController.h"#import"SecondTableViewController.h"#import"ThirdTableViewController.h"#import"FourthTableViewController.h"#import"FiveTableViewController.h"#import"SixTableViewController.h"@interface appdelegate ()<UITabBarControllerDelegate>@end @implementation appdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {Self.window=[[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]] autorelease]; //Override point for customization after application launch.Firsttableviewcontroller*FIRSTVC =[[Firsttableviewcontroller alloc] init]; FirstVC.tabBarItem.title=@"message"; FirstVC.tabBarItem.image= [UIImage imagenamed:@"Tabbar_mainframe"]; FirstVC.tabBarItem.badgeValue=@"NEW"; //set the picture after selection//firstVC.tabBarItem.selectedImage = [UIImage imagenamed:@ "tabbar_contacts"];FirstVC.tabBarItem.tag = -; Uinavigationcontroller*FIRSTNVC =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:FIRSTVC]; Secondtableviewcontroller*SECONDVC =[[Secondtableviewcontroller alloc] init]; SecondVC.tabBarItem.title=@"Contacts"; SecondVC.tabBarItem.image= [UIImage imagenamed:@"tabbar_contacts"]; SecondVC.tabBarItem.badgeValue=@"1"; SecondVC.tabBarItem.tag=101; Thirdtableviewcontroller*THIRDVC =[[Thirdtableviewcontroller alloc] init]; ThirdVC.tabBarItem.title=@"found"; ThirdVC.tabBarItem.image= [UIImage imagenamed:@"Tabbar_discover"]; ThirdVC.tabBarItem.tag=102; Fourthtableviewcontroller*FOURTHVC =[[Fourthtableviewcontroller alloc] init]; FourthVC.tabBarItem.title=@"my own"; FourthVC.tabBarItem.image= [UIImage imagenamed:@"Tabbar_me"]; FourthVC.tabBarItem.tag=103; Fivetableviewcontroller*FIVEVC =[[Fivetableviewcontroller alloc] init]; FiveVC.tabBarItem.title=@"Download"; FiveVC.tabBarItem.image= [UIImage imagenamed:@"Qr_toolbar_online_download_hl"]; Sixtableviewcontroller*SIXVC =[[Sixtableviewcontroller alloc] init]; SixVC.tabBarItem.title=@"Tools"; SixVC.tabBarItem.image= [UIImage imagenamed:@"Qr_toolbar_more_hl"]; //Create a label view ControllerUitabbarcontroller *TABBARVC =[[Uitabbarcontroller alloc] init]; //1. Configure multiple view controllers managed by the label ControllerNsarray *viewcontrllers =@[firstnvc, SECONDVC, THIRDVC, FOURTHVC,FIVEVC, SIXVC]; Tabbarvc.viewcontrollers=viewcontrllers; //2. Modify the color of the tab barTabBarVC.tabBar.barTintColor =[Uicolor Whitecolor]; //3. Modify the rendering color of the tab barTabBarVC.tabBar.tintColor =[Uicolor Greencolor]; //4. Set the default selected label//Tabbarvc.selectedindex = 2; //Set the default selected View ControllerTabbarvc.selectedviewcontroller =THIRDVC; //5. Set a picture for Tabbar//tabBarVC.tabBar.backgroundImage = [UIImage imagenamed:@ "320x49"];TABBARVC.Delegate=Self ; //designate a label controller as the root view controller for WindowsSelf.window.rootViewController =TABBARVC;    [FIRSTVC release];    [SECONDVC release];    [THIRDVC release];                                [FOURTHVC release]; Self.window.backgroundColor=[Uicolor Whitecolor];    [Self.window makekeyandvisible]; returnYES;}#pragmaMark//ask if the label can be selected-(BOOL) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Shouldselectviewcontroller: (UIViewController *) Viewcontroller {//NSLog (@ "%s,%d", __function__,__line__);    returnYES;}//triggered when the label is selected- (void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Didselectviewcontroller: (Uiviewcontroller *) viewcontroller{//NSLog (@ "%s,%d", __function__,__line__);    if(101==viewController.tabBarItem.tag) {ViewController.tabBarItem.badgeValue=Nil; }}//triggered when you are about to start specifying multiple view controllers that are managed by the label View controller (triggered when you click the Edit button in the more)- (void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller willbegincustomizingviewcontrollers: (NSArray *) Viewcontrollers {//NSLog (@ "%s,%d", __function__,__line__);}//triggered when the tab bar is finished editing.- (void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller didendcustomizingviewcontrollers: (NSArray *) Viewcontrollers changed: (BOOL) changed{//NSLog (@ "%s,%d", __function__,__line__);}- (void) Applicationwillresignactive: (UIApplication *) Application {//Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US    Er quits the application and it begins the transition to the background state. //Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void) Applicationdidenterbackground: (UIApplication *) Application {//Use the method to release the shared resources, save user data, invalidate timers, and store enough application state in    Formation to the restore your application to the it is terminated later. //If Your application supports background execution, this method is called instead of Applicationwillterminate:when th E user quits.}- (void) Applicationwillenterforeground: (UIApplication *) Application {//Called as part of the transition from the background to the inactive state; Here you can undo many of the changes mad E on entering the background.}- (void) Applicationdidbecomeactive: (UIApplication *) Application {//Restart Any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.}- (void) Applicationwillterminate: (UIApplication *) Application {//Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.}-(void) dealloc{Self.window=Nil; [Super Dealloc];} @end

Uitabbarcontroller in iOS (Tag view controller)

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.