Multi-Controller management in iOS (ii)-uitabbarcontroller-

Source: Internet
Author: User

Uitabbarcontrolleruitabbarcontroller Introduction
    • Similar to Uinavigationcontroller, Uitabbarcontroller can easily manage multiple controllers, easily switch between controllers, typical examples are QQ, and other applications

Uitabbarcontroller simple use of uitabbarcontroller steps
初始化UITabBarController设置UIWindow的rootViewController为UITabBarController根据具体情况,通过addChildViewController方法添加对应个数的子控制器
Uitabbarcontroller Sub-Controller Uitabbarcontroller add a controller in 2 ways add a single sub-controller
- (void)addChildViewController:(UIViewController *)childController;
Set up a sub-controller array
@property(nonatomicNSArray *viewControllers;
Simple creation of Uitabbarcontroller
 //1. Create a window     Self. Window= [[UIWindowAlloc] Initwithframe:[uiscreen Mainscreen]. Bounds];//2. Create Tabbarcontroller    Uitabbarcontroller*tabbarcontroller = [[UitabbarcontrollerALLOC] init];//3. Setting the window root controller     Self. Window. Rootviewcontroller= Tabbarcontroller;//3.1 Create three sub-controllers    Uiviewcontroller*VC1 = [[UiviewcontrollerALLOC] init]; Vc1. View. BackgroundColor= [UicolorRedcolor];Uiviewcontroller*VC2 = [[UiviewcontrollerALLOC] init]; Vc2. View. BackgroundColor= [UicolorGreencolor];Uiviewcontroller*VC3 = [[UiviewcontrollerALLOC] init]; Vc3. View. BackgroundColor= [UicolorBluecolor];//[tabbarcontroller ADDCHILDVIEWCONTROLLER:VC1];    //[tabbarcontroller ADDCHILDVIEWCONTROLLER:VC2];    //[tabbarcontroller ADDCHILDVIEWCONTROLLER:VC3];Tabbarcontroller. Viewcontrollers= @[vc1,vc2,vc3];//4. Display[ Self. WindowMakekeyandvisible];
Uitabbar
    • If the Uitabbarcontroller has n sub-controllers, there will be N Uitabbarbutton as child controls inside the Uitabbar

    • If the Uitabbarcontroller has 4 sub-controllers, then the Uitabbar structure is roughly as shown

Uitabbarbutton

App Mainstream framework Structure

Segue Introduction
    • Each line on the storyboard for interface jumps is a Uistoryboardsegue object (abbreviated segue)

Segue properties for each Segue object, there are 3 properties
唯一标识@property (nonatomicreadonlyNSString *identifier;来源控制器@property (nonatomicreadonlyid sourceViewController;目标控制器@property (nonatomicreadonlyid destinationViewController;

The type of segue according to the Segue execution (jump) moment, segue can be divided into 2 major types
自动型:点击某个控件后(比如按钮),自动执行Segue,自动完成界面跳转手动型:需要通过写代码手动执行Segue,才能完成界面跳转
Automatic type Segue
按住Control键,直接从控件拖线到目标控制器点击“登录”按钮后,就会自动跳转到右边的控制器如果点击某个控件后,不需要做任何判断,一定要跳转到下一个界面,建议使用“自动型Segue”

Manual type Segue
按住Control键,从来源控制器拖线到目标控制器手动型的Segue需要设置一个标识在恰当的时刻,使用perform方法执行对应的Segue
[selfperformSegueWithIdentifier:@"login2contacts"sender:nil];//Segue必须由来源控制器来执行,也就是说,这个perform方法必须由来源控制器来调用
如果点击某个控件后,需要做一些判断,也就是说:满足一定条件后才跳转到下一个界面,建议使用“手动型Segue”

The Performseguewithidentifier method uses the Performseguewithidentifier: method to perform a segue, completing the interface jump next study Performseguewithidentifier: Sender: The full execution of the method
[selfperformSegueWithIdentifier:sender:nil];// 这个self是来源控制器
According to identifier to find the corresponding line in the storyboard, create a new Uistoryboardsegue object
设置Segue对象的sourceViewController(来源控制器)新建并且设置Segue对象的destinationViewController(目标控制器)
Call Sourceviewcontroller The following method, do some pre-jump preparation and pass in the created Segue object
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender;// 这个sender是当初performSegueWithIdentifier:sender:中传入的sender
Call the-(void) Perform of the Segue object; method starts the interface jump operation if the segue style is push
取得sourceViewController所在的UINavigationController调用UINavigationController的push方法将destinationViewController压入栈中,完成跳转
If Segue's style is modal
调用sourceViewController的presentViewController方法将destinationViewController展示出来
Transfer of sender Parameters

Data transfer between controller data transfer controller has 2 main cases: Shun and inverse transmission
控制器的跳转方向: A 往 C数据的传递方向: A 往 C数据的传递方式: 在A的prepareForSegue:sender:方法中根据segue参数取得destinationViewController, 也就是控制器C, 直接给控制器C传递数据(要在C的viewDidLoad方法中取得数据,来赋值给界面上的UI控件)

Reverse transmission
控制器的跳转方向: A 往 C数据的传递方向: C 往 A数据的传递方式: 让A成为C的代理, 在C中调用A的代理方法,通过代理方法的参数传递数据给A

Multi-Controller management in iOS (ii)-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.