(90) Separate management of the controller using multiple storyboard+ codes

Source: Internet
Author: User

Using a single storyboard makes the project difficult and manageable, and using pure code can be cumbersome, so if you combine the two and use multiple storyboard, it makes the project simple and convenient.

The following is an example of a simple view relationship that describes the use of multiple storyboard.

① have Page1 and page2 two pages, click on the detail button Page1 will pop up page1detail view, click the Page1detail return button will return.

②page1 and Page2 switch through Tabbar.

We create Page1, Page2, Page1detail three storyboard, each with its own controller, note that each controller is initial viewcontroller, otherwise it crashes when the storyboard controller is loaded .

"Concrete Steps"

① Delete the default settings for main interface in the project settings, because to connect two controllers with Tabbar, it should be implemented by code.

② creates a window in Appdelegate, creates a tabbar, and sets the rootviewcontroller of the window to Tabbar.

Load storyboard, get the default controller from storyboard, then set Tabbar viewcontrollers to Page1, Page2, and finally don't forget to call the Makekeyandvisible Method of window.


-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {        Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];        Self.window.backgroundColor = [Uicolor whitecolor];        Uitabbarcontroller *TB = [[Uitabbarcontroller alloc] init];        Load Storyboard    Uistoryboard *PAGE1SB = [Uistoryboard storyboardwithname:@ "Page1" bundle:nil];    Uistoryboard *PAGE2SB = [Uistoryboard storyboardwithname:@ "Page2" bundle:nil];    Created and added to Tabbar    tb.viewcontrollers = @[page1sb.instantiateinitialviewcontroller, Page2sb.instantiateinitialviewcontroller];        Self.window.rootViewController = TB;        [Self.window makekeyandvisible];        return YES;}

By this setting, the Tabbar can be implemented with a Page1, Page2 two controllers.


③ modal a detail controller when clicking the Detail button in Page1, the same is done by loading storyboard, getting the default controller, calling Presentviewcontroller::: Method modal this controller.

-(Ibaction) Detailclick: (ID) Sender {        //load Storyboard    uistoryboard *detailsb = [Uistoryboard storyboardwithname:@ "Page1detail" bundle:nil];    Create Controller    Uiviewcontroller *VC = Detailsb.instantiateinitialviewcontroller;    [Self PRESENTVIEWCONTROLLER:VC animated:yes completion:nil];    }

The return of the ④modal controller is implemented through dismiss.

-(Ibaction) Backclick: (ID) Sender {        [self dismissviewcontrolleranimated:yes completion:nil];    }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

(90) Separate management of the controller using multiple storyboard+ codes

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.