Dynamically add uiviewcontroller to the storyboard

Source: Internet
Author: User

Storyboard is one of the new features of ios5. It makes the design of the program view into a drawing board, which allows the boring programmers to experience the next painter. If I first came into contact with storyboard and wanted to use storyboard for the simplest IOS program, I suggest you click the portal. This is a good getting started tutorial with a lot of images.

Previously, the file's owner was used to load view resources and code the relationship between viewcontrollers. Now, storyboard builds the relationship between viewcontrollers through uistoryboardsegue (my translation is a endurance, that is to say, the conversion between viewcontrollers (replace, push, popover, and modal) controlled by code can be visually passed through the "line" of storyboard (actually the original code is complete, now it is automatically completed by using xcode.

When using storyboard at the beginning, I always feel that it is difficult to start. I only use segues automatically created by xcode. I need to reorganize the storyboard concept. storyboard is not a complete solution, that is, it is not necessary to replace all XIB with storyboard. I can create a completely independent viewcontroller on the storyboard, or use the storyboard only as part of my program. To put it bluntly, it is "mashups", where storyboard and XIB are used together with code (only for creating viewcontroller) to achieve the development efficiency and flexibility of xocde, the difficulty of getting started is fully balanced with the function.

Let's take a specific example. For example, we should first create a tabbed aplicaiton, which contains two viewcontrollers, one first View Controller and one second View Controller. We want to dynamically create the third viewcontroller, that is to say, the tab below is changed to three options, code portal.

Several steps are required to use an independent view controller on the storyboard.

1. Add a separate View Controller to the storyboard.

2. Complete the identifier settings in the inspector of the View Controller.


 

3. Use uistoryboard class to load storyboard Resources

4. Use [uistoryboard instantiateviewcontrollerwithidentifier:] to create a New View Controller instance.

5. Use the View Controller as needed

Uistoryboard * storyboard; uiviewcontroller * VC; // obtain uitabbarcontroller TB = self. tabbarcontroller; viewcontrollers = [[nsmutablearray alloc] initwitharray: TB. viewcontrollers]; storyboard = [uistoryboard storyboardwithname: @ "mainstoryboard" Bundle: Nil]; Vc = [storyboard instantiateviewcontrollerwithidentifier: @ "thirdviewcontroller"];

 

The overall code is relatively simple, so there is nothing to do. I will share my thoughts on solving the problem, and I will leave a message for the children's shoes in question,


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.