IOS Development UI Build Experience (a)--harness StoryBoard

Source: Internet
Author: User

In this series of articles, we will be able to learn about several common UI constructs in IOS development, analyze their respective usage scenarios, so that we can make the best choice in the future development, improve the development efficiency and enhance the maintainability of the program in the right time and scene. As the beginning of this article, we will try to harness the powerful Storyboard together.

The essence of StoryBoard

StoryBoard is the new technology introduced by Apple in IOS 5 to give a warm home to the complex nib, xib, and make their relationship more visually visible, and provides a new way of jumping between pages segue.

The essence of StoryBoard is an XML file that describes key information such as forms, components, Auto Layout constraints, and so on. Sample file: Https://github.com/johnlui/AutoLayout/blob/master/AutoLayout/Base.lproj/Main.storyboard

However, we should recognize a more important essence: IOS projects that use StoryBoard initialize the StoryBoard file as an initialization entry for the entire program, and the Uiviewcontroller class is initialized by the StoryBoard binding. To start running. You can find clues from the following two places:

Strange bug.

Beginner IOS Development, if the use of StoryBoard, you may have encountered this strange bug, the page is All Black:

If you like me purely by looking for information on self-study and no one teaches, there must be no reason to find the cause of the embarrassing situation of a new project O (╯-╰) O, in fact, the secret here:

This means that the form is meant to be the initial form of this StoryBoard, so that when the app starts, it starts the main StoryBoard, the primary StoryBoard launches its initial form, the initial form launches the class that binds him, and the app starts to complete.

Multi-StoryBoard Best practices

TOEFL Meow "has been off the shelf" version 1.0 is my first listing of the project, only with the initialization of the project when the only Main.storyboard built, there are more than 20 forms, in Xcode each click Open to wait five seconds to complete the full rendering, and Segue line staggered horizontal, very messy. This is obviously not a good way to organize.

I am now rewriting the second version of the TOEFL Meow has adopted a multi-StoryBoard solution, put some separate form combinations together using a StoryBoard to organize, such as landing several forms of registration, examination interface of several forms, about our several forms and so on. Below we will learn how to use multiple StoryBoard together.

Create a second StoryBoard

Such as:

Drag Second.storyboard into a View Controller:

How do I call a form in Second.storyboard?

First, compile the project and we get the following warning:

This warning means that the form has no entry and cannot be reached. How to get him to be touched? Two different ways:

Set the initial form for the StoryBoard:

Set a StoryBoard ID for the form:

After being able to get reached, let's call them in code:

① as the initial form

Let VC = Uistoryboard (name: "Second", Bundle:nil). Instantiateinitialviewcontroller () as! Uiviewcontrollerself.navigationcontroller?. Pushviewcontroller (VC, Animated:true)

② Set the StoryBoard ID

Let VC = Uistoryboard (name: "Second", Bundle:nil). Instantiateviewcontrollerwithidentifier ("first") as! Uiviewcontrollerself.navigationcontroller?. Pushviewcontroller (VC, Animated:true)

Of course, they can also be called with Self.presentviewcontroller .

View Effects

Auto Layout

Auto Layout with StoryBoard is a perfect match, with tacit understanding, can greatly improve the efficiency of UI development, one-time make suitable for all screen size UI. For more information on how to use auto layout, you can refer to the Auto Layout Usage series article.

IOS Development UI Build Experience (a)--harness StoryBoard

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.