"iOS base control 15-2" Uitabbarcontroller Controller Management

Source: Internet
Author: User

A. Requirements1. Similar to QQ, top or bottom of the window conversion navigation bar 2. Add content to each page B.uitabbarcontroller1. Basic concept: (1) Content height iOS7 before content height: screen height-status bar height 44-bottom navigation bar height 49ios7 and after, content height is full screen 2. Using code creation Initialization (1) to create a Uitabbarcontrolleruitabbarcontroller use step
    • Initialize Uitabbarcontroller
    • Set the Rootviewcontroller for UIWindow to Uitabbarcontroller
    • Depending on the case, add the corresponding number of sub-controllers by the Addchildviewcontroller method
(2) Add a sub-controller Uitabbarcontroller There are 2 ways to add a controller
    • Adding a single child controller
-(void) Addchildviewcontroller: (Uiviewcontroller *) Childcontroller;

    • Set up a sub-controller array
@property (nonatomic,copy) Nsarray *viewcontrollers;  If the Uitabbarcontroller has n sub-controllers, then there will be N Uitabbarbutton inside Uitabbar as child controls if Uitabbarcontroller has 4 sub-controllers, then the structure of Uitabbar is roughly as shown Appdelegate:
 1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {2// Override point for customization after application launch. 3 4//Set window 5 Self.window = [[UIWindow alloc] init]; 6 self.window.frame = [[UIScreen mainscreen] bounds]; 7 Self.window.backgroundColor = [Uicolor Graycolor]; 8 [Self.window makekeyandvisible]; 9 10 11//Set a UITabBarController12 uitabbarcontroller *tabbarcontroller = [[Uitabbarcontroller alloc] init] ; Self.window.rootViewController = tabbarcontroller;14 15//Add sub-controller Uiviewcontroller *c1 = [[Uiviewcont Roller Alloc] init];17 c1.view.backgroundColor = [Uicolor redcolor];18//[Tabbarcontroller Addchildviewcontroller: c1];19 Uiviewcontroller *c2 = [[Uiviewcontroller alloc] init];21 c2.view.backgroundColor = [Uicolor Bluecolo R];22//[Tabbarcontroller addchildviewcontroller:c2];23 uiviewcontroller *c3 = [UiviewcontroLler alloc] init];25 c3.view.backgroundColor = [Uicolor greencolor];26] tabbarcontroller.viewcontrollers = @[ c1,c2,c3];28 return yes;31}
(3) Set the navigation bar option style Uitabbarbutton What is displayed inside, determined by the Tabbaritem property of the corresponding sub-controller


Uitabbaritem has the following properties that affect the content of Uitabbarbutton
Title text
@property (nonatomic,copy) NSString *title;

Icon
@property (Nonatomic,retain) UIImage *image;

Icon When selected
@property (Nonatomic,retain) UIImage *selectedimage;

Reminder number @property (nonatomic,copy) NSString *badgevalue; Appdelegate:
 1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {2// Override point for customization after application launch. 3 4//Set window 5 Self.window = [[UIWindow alloc] init]; 6 self.window.frame = [[UIScreen mainscreen] bounds]; 7 Self.window.backgroundColor = [Uicolor Graycolor]; 8 [Self.window makekeyandvisible]; 9 10 11//Set a UITabBarController12 uitabbarcontroller *tabbarcontroller = [[Uitabbarcontroller alloc] init] ; Self.window.rootViewController = tabbarcontroller;14 15//Add sub-controller Uiviewcontroller *c1 = [[Uiviewcont Roller Alloc] init];17 c1.view.backgroundColor = [Uicolor redcolor];18 c1.tabBarItem.title = @ "Red"; +//[Tabba Rcontroller addchildviewcontroller:c1];20 Uiviewcontroller *c2 = [[Uiviewcontroller alloc] init];22 C2.view. BackgroundColor = [Uicolor bluecolor];23 c2.tabBarItem.title = @ "Blue"; +//[Tabbarcontroller Addchildviewcontroller:c2];25 Uiviewcontroller *c3 = [[Uiviewcontroller alloc] init];27 c3.view.backgroundColor = [ Uicolor greencolor];28 c3.tabBarItem.title = @ "green"; tabbarcontroller.viewcontrollers = @[c1,c2,c3];31 3 2 Return yes;34}
3. Use storyboard to create initialization (1) drag into Uitabbarcontroller (2) drag into n Uiviewcontroller to use (3) to set the Uitabbarcontroller sub-controller in sequence (4) Set the Tabbaritem out of the sub-controller: Note: Selected image is not set, the system will automatically program the original artwork blue as Selected image4. The life cycle of the sub-controller (1) The life cycle of a single sub-controller is the same as the normal controller life cycle
 1-(void) Viewdidload {2 [Super Viewdidload]; 3 NSLog (@ "%@-viewdidload", Self.class); 4} 5 6-(void) Viewwil Lappear: (BOOL) animated {7 [Super viewwillappear:animated]; 8 NSLog (@ "%@-viewwillappear", Self.class); 9}10 11 -(void) Viewdidappear: (BOOL) animated {[Super viewdidappear:animated];13 NSLog (@ "%@-viewdidappear", Self.class );}15-(void) Viewwilldisappear: (BOOL) animated {[Super viewwilldisappear:animated];18 NSLog (@ "%@-vieww     Illdisappear ", self.class);}20-(void) Viewdiddisappear: (BOOL) animated {[Super viewdiddisappear:animated];23 NSLog (@ "%@-viewdiddisappear", Self.class),}25-(void) didreceivememorywarning [[Super Didreceivememo] rywarning];29 NSLog (@ "%@-didreceivememorywarning", Self.class),}31-(void) Viewwillunload {[+] [Super VIEWW Illunload];34 NSLog (@ "%@-viewwillunload", self.class);}36 Notoginseng-(void) viewdidunload {[] [super viewdidunload]; NSLog (@ "%@-ViewDidunload ", self.class); 40} 
(2) Life cycle of two sub-controller transitions A. The first child controller appears view 2014-12-27 21:11:44.338 uitabbarcontrollerbystoryboard[22567:590996] Oneviewcontroller-viewdidload
2014-12-27 21:11:44.340 uitabbarcontrollerbystoryboard[22567:590996] oneviewcontroller-viewwillappear
2014-12-27 21:11:44.407 uitabbarcontrollerbystoryboard[22567:590996] oneviewcontroller-viewdidappearB. Switching to a second controller view 2014-12-27 21:12:10.042 uitabbarcontrollerbystoryboard[22567:590996] Twoviewcontroller-viewdidload
2014-12-27 21:12:10.042 uitabbarcontrollerbystoryboard[22567:590996] Twoviewcontroller-viewwillappear
2014-12-27 21:12:10.042 uitabbarcontrollerbystoryboard[22567:590996] Oneviewcontroller-viewwilldisappear
2014-12-27 21:12:10.054 uitabbarcontrollerbystoryboard[22567:590996] oneviewcontroller-viewdiddisappear
2014-12-27 21:12:10.055 uitabbarcontrollerbystoryboard[22567:590996] twoviewcontroller-viewdidappear C.app FrameWrap the previous Navigationcontroller before each sub-controller

"iOS base control 15-2" Uitabbarcontroller Controller Management

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.