IOS development-UI (11) UITabBarController and iosui Development

Source: Internet
Author: User

IOS development-UI (11) UITabBarController and iosui Development

Knowledge point:

1. Use UITabBarController

2. Use UITabBarItem

 

For more information about TabBarController, refer to the two articles I have posted before. They are useful in actual development.

The basic usage of RDVTabBarController and the prevention of Dual-click of tabbar jump from the Controller on one item of tabBarController to the Controller on another item

 

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

UITabBarController

1. Creation Method

2. How to add a UIViewController to UITabBarController

3. How to add a UINavigationController to UITabBarController

4. Remember the order of clicks

5. Set and obtain the selected items

@ Property (nonatomic) NSUInteger selectedIndex;

 

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

UITabBarItem

 

1. Relationship between UITabBarItem and UITabBarController

TabBarItem is an attribute of UIViewController.

This attribute serves UITabBarController.

2. Create UITabBarItem for text and images

-(Id) initWithTitle :( NSString *) title

Image :( UIImage *) image

Tag :( NSInteger) tag;

 

-(Instancetype) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) nibBundleOrNil {if (self = [super initWithNibName: nibNameOrNil bundle: callback]) {// set text self with image type. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "red" image: [UIImage imageNamed: @ "incluselected"] tag: 0]; // set text, selected image type and unselected image type // self. tabBarItem = [[UITabBarItem alloc] initWithTitle: @ "red" image: [UIImage imageNamed: @ "3_normal"] selectedImage: [UIImage imageNamed: @ "3_selected"];}

 

 

Note: functions added after ios7

-(Instancetype) initWithTitle :( NSString *) title

Image :( UIImage *) image

SelectedImage :( UIImage *) selectedImage

 

3. Create UITabBarSystemItem

-(Id) initWithTabBarSystemItem :( UITabBarSystemItem) systemItem

Tag :( NSInteger) tag;

 

// Set the system type self. tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem: UITabBarSystemItemTopRated tag: 0];

 

 

4. Set UITabBarItem logo

@ Property (nonatomic, copy) NSString * badgeValue

// Set the logo self. tabBarItem. badgeValue = [NSString stringWithFormat: @ "% ld", 10L];

 

 

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

UITabBarController usage instructions

1. UITabBarController quantity limit

1) Up to five attempt controllers can be displayed in tabBarController.

The system automatically adds a more

2. Edit UITabBarController

You can set the display position of each control at will.

 

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

UITabBarController Sequence

1. Record the viewController you last clicked

1) NSUserDefaults

The NSUserDefaults object is used to save and restore preference settings and configuration data related to the application.

2) create NSUserDefaults

+ (NSUserDefaults *) standardUserDefaults

3) Data Storage

-(Void) set [data type] :( data type) value forKey :( NSString *) defaultName;

4) synchronize data

-(BOOL) synchronize;

5) read data

-(Data type) [data type] ForKey :( NSString *) defaultName;

 

2. Use UITabBarControllerDelegate

1) When selected

-(Void) tabBarController :( UITabBarController *) tabBarController

DidSelectViewController :( UIViewController *) viewController

# Pragma mark-UITabBarControllerDelegate // you have selected a controller-(void) tabBarController :( UITabBarController *) tabBarController didSelectViewController :( UIViewController *) viewController {NSLog (@ "the currently selected controller subscript is % ld", tabBarController. selectedIndex); // record NSUserDefaults * def = [NSUserDefaults standardUserDefaults]; [def setInteger: tabBarController. selectedIndex forKey: @ "index"]; // synchronize to local [def synchronize];}

 

 

2) control whether TabBarItem can be selected

-(BOOL) tabBarController :( UITabBarController *) tabBarController

ShouldSelectViewController :( UIViewController *) viewController;

// Select a controller (whether the controller can be selected)-(BOOL) tabBarController :( UITabBarController *) tabBarController shouldSelectViewController :( UIViewController *) viewController {// The Controller object to be selected by viewController // The partition controller managed by tabBarController // NSLog (@ "the currently selected controller subscript is % ld", tabBarController. selectedIndex);/* incorrect syntax: The first controller if (tabBarController. selectedIndex = 0) {return NO;} */if (viewController = tabBarController. viewControllers [0]) {return NO;} // return YES, which can be selected, NO is returned, and return YES ;}

 

 

3) the following three methods are mainly used to monitor the edit operation on the view controller in the moreViewController.

# Pragma mark-marker // prepare for editing-(void) tabBarController :( UITabBarController *) tabBarController willBeginCustomizingViewControllers :( NSArray *) viewControllers {NSLog (@ "alert");} 2. // prepare to stop editing-(void) tabBarController :( UITabBarController *) tabBarController willEndCustomizingViewControllers :( NSArray *) viewControllers changed :( BOOL) changed {NSLog (@ "willEndCustomizingViewControllers");} 3. // edit ended-(void) tabBarController :( UITabBarController *) tabBarController didendmizmizingviewcontrollers :( NSArray *) viewControllers :( BOOL) changed {// determine whether the order is changed if (changed) {// record the title sequence NSMutableArray * newArr = [NSMutableArray new]; for (UIViewController * ctl in viewControllers) {[newArr addObject: ctl. title];} // save it to the local NSUserDefaults * def = [NSUserDefaults standardUserDefaults]; [def setObject: newArr forKey: @ "saveArr"]; [def synchronize];}

 

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.