iOS Development-ui (11) Uitabbarcontroller

Source: Internet
Author: User

Knowledge Points:

1.UITabBarController use

2.UITabBarItem use

About Tabbarcontroller In addition to the contents of this finishing, interested can look at the two I have sent before, in the actual development of practical things.

Basic use of rdvtabbarcontroller and Tabbar to prevent double-click Methodjump from the controller on one item on the Tabbarcontroller to the controller on the other item

=======================

Uitabbarcontroller

1. How to create

2. How to add a Uiviewcontroller to Uitabbarcontroller

3. How to add a Uinavigationcontroller to Uitabbarcontroller

4. How to remember the click order

5. Set and get selected items

@property (nonatomic) Nsuinteger SelectedIndex;

=======================

Uitabbaritem

1.UITabBarItem and Uitabbarcontroller relationships

Tabbaritem is a property of Uiviewcontroller

This property is for Uitabbarcontroller service.

2. Create uitabbaritem for text and pictures

-(ID) Initwithtitle: (NSString *) title

Image: (UIImage *) image

Tag: (nsinteger) tag;

-(Instancetype) Initwithnibname: (NSString *) Nibnameornil Bundle: (NSBundle *) nibbundleornil{if(self =[Super Initwithnibname:nibnameornil Bundle:nibbundleornil]) {//sets the text with the type of the pictureSelf.tabbaritem= [[Uitabbaritem alloc] Initwithtitle:@"Red"Image:[uiimage imagenamed:@"1_selected"] Tag:0]; //set text, select picture and unchecked picture type//Self.tabbaritem = [[Uitabbaritem alloc] initwithtitle:@ "Red" image:[uiimage imagenamed:@ "3_normal"] selectedImage: [UIImage imagenamed:@ "3_selected"];}

Note: The function added after iOS7

-(Instancetype) Initwithtitle: (NSString *) title

Image: (UIImage *) image

SelectedImage: (UIImage *) selectedimage

3. Create the Uitabbarsystemitem that comes with your system

-(ID) Initwithtabbarsystemitem: (Uitabbarsystemitem) Systemitem

Tag: (nsinteger) tag;

// Set System Type  = [[Uitabbaritem alloc] initwithtabbarsystemitem:uitabbarsystemitemtoprated tag:0];

4. Setting the Uitabbaritem logo

@property (nonatomic,copy) NSString *badgevalue

// set up a logo  = [NSString stringWithFormat:@ "%ld",10L];

=======================

Uitabbarcontroller Use note

1.UITabBarController Quantity Limit

1) up to 5 attempts in Tabbarcontroller are allowed

The exceeded system will automatically add a more

2.UITabBarController editing

User can set the display position of each control at will

=======================

Uitabbarcontroller Order

1. Record the viewcontroller of the user's last click

1) Nsuserdefaults effect

Nsuserdefaults objects are used to save, restore application-related preferences, configuration data, and so on

2) Nsuserdefaults creation

+ (Nsuserdefaults *) Standarduserdefaults

3) Store data

-(void) set[data type]:(data type) value Forkey: (NSString *) DefaultName;

4) Synchronizing Data

-(BOOL) synchronize;

5) Read Data

-(data type) [Data type]forkey: (NSString *) DefaultName;

2.UITabBarControllerDelegate use

1) When you are selected

-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller

Didselectviewcontroller: (Uiviewcontroller *) Viewcontroller

#pragmaMark-uitabbarcontrollerdelegate//A controller has been selected-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Didselectviewcontroller: (Uiviewcontroller *) viewcontroller{NSLog (@"The controller that is currently selected is labeled%ld", Tabbarcontroller.selectedindex); //RecordNsuserdefaults*def =[Nsuserdefaults Standarduserdefaults]; [Def setInteger:tabBarController.selectedIndex Forkey:@"Index"]; //sync to local[def Synchronize];}

2) control Tabbaritem can be selected

-(BOOL) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller

Shouldselectviewcontroller: (Uiviewcontroller *) Viewcontroller;

//prepare to select a controller (whether the controller can be selected)-(BOOL) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller Shouldselectviewcontroller: (UIViewController *) viewcontroller{//Viewcontroller the Controller object to be selected//Tabbarcontroller currently managed columns Controller//NSLog (@ "Currently selected controller is labeled%ld", tabbarcontroller.selectedindex);    /*wrong wording: Do not allow the first controller to be selected if (Tabbarcontroller.selectedindex = = 0) {return no; }     */    if(Viewcontroller = = tabbarcontroller.viewcontrollers[0]) {        returnNO; }    //returns Yes, can be checked, returns no, does not allow selection    returnYES;}

3) The following three methods are mainly used to monitor the edit operation of the view controller in Moreviewcontroller

 #pragmaMark-uitabbarcontrollerdelegate1.//ready to start editing-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller willbegincustomizingviewcontrollers: (NSArray *) viewcontrollers{NSLog (@"willbegincustomizingviewcontrollers");}2.//prepare to finish editing-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller willendcustomizingviewcontrollers: (NSArray *) Viewcontrollers changed: (BOOL) changed{NSLog (@"willendcustomizingviewcontrollers");} 3.//has finished editing-(void) Tabbarcontroller: (Uitabbarcontroller *) Tabbarcontroller didendcustomizingviewcontrollers: (NSArray *) Viewcontrollers changed: (BOOL) changed{//determine if the order has changed    if(changed) {//Record title OrderNsmutablearray*newarr = [NsmutablearrayNew];  for(Uiviewcontroller *ctlinchviewcontrollers)                {[NewArr addObject:ctl.title]; }            //Save to localNsuserdefaults*def =[Nsuserdefaults Standarduserdefaults]; [Def Setobject:newarr Forkey:@"Savearr"];         [Def Synchronize]; }}

iOS Development-ui (11) Uitabbarcontroller

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.