Xcode4.2 change the second storyboard

Source: Internet
Author: User

3. New Feature-storyboard

Storyboard is another new feature of xcode4.2. It integrates all the XIB files in the original project and creates a jump relationship between viewcontroller objects by dragging, makes the UI jump logic of the entire program clear. Simply put, storyboard introduces two concepts:

Scene: a scenario, represented by a viewcontroller and related XIB.

Segue: (in english ). This is used to connect scenes and has multiple types, including push, modal, and popover.
And more.

Of course, segue is also responsible for transmitting data and returning data.

The Interface Conversion of the entire program is to switch between various scene. The interface jump relationship, such as the interface to which the key is clicked, is described by the segue. Segue can also contain data for data transmission. (It is also said that Adobe Flash is copied ).

Key point: you must have a viewcontroller that serves as the initial interface of the storyboard and check the initial scene item. For example:

 

Advantages of storyboard over nib/XIB:

  • This reduces the amount of view-related code.
  • The view and controller can be further decoupled.
  • Optimize the "Page stream" of the program to make the program structure clearer.

Generally, NiB is associated with viewcontroller. In many cases, viewcontroller has its corresponding NIB file. This file is used to describe the user interface and initialize objects and Interface Element objects. Although these can be implemented in the code, xcode provides IB to draw the interface in order to efficiently write the program code. The introduction of storyboard further strengthens this function. The previous NIB file cannot describe the jump transition between viewcontrollers. It can only be called through code similar to-presentmodalviewcontroller: animated: or-pushviewcontroller: animated: these two methods are implemented. Now, the concept of segue is introduced in storyboard, which defines the transition from one viewcontroller to another. You only need to connect the interface object and action as before.
In this way, the viewcontroller can be connected with a suitable segue without any handwritten code. Even a custom segue, you only need to write the implementation of the segue without writing the called code. Everything is called by storyboard for us.

To make full use of the storyboard mechanism accurately, we must strictly abide by the MVC principles. The view and controller should be fully decoupled, and different controllers should also be fully decoupled. Therefore, appdelegate should be responsible for processing the callback of the uiapplication, rather than processing the user interface. We should not directly use appdelegate as viewcontroller, or even draw the interface directly on the uiwindow. Although this may be simple and clear, after all, uiwindow is also a subclass of uiview. But we still need to have a good habit: viewcontroller is responsible for processing the view, which is the right way. Apple's recent changes to xcode project templates also reflect this optimization trend:

In xcode 4, the Program Project template (such as view-based application) encourages the use of the rootviewcontroller attribute of uiwindow to specify the viewcontroller of the first screen, to ensure that appdelegate only focuses on what it should do. Now, after xcode4.2 introduces storyboard, appdelegate does not care about viewcontroller. The viewcontroller (rootviewcontroller) used on the first screen can be set in storyboard.

How to migrate data from nib/XIB to storyboard?

  • Viewcontroller does not need a nib/XIB file. The operations for connecting outlet and action can be completed on storyboard.
  • Isolated view (view independent from viewcontroller) cannot appear in storyboard, and all views must be managed through viewcontroller. (In this way, storyboard is more like a controller object container than a view object container. Previously, NIB/XIB can be regarded as a view object container)
  • The transition code between viewcontrollers is no longer needed. You can use the storyboard segue to directly connect different viewcontrollers.
  • The role of the uiwindow object is further reduced, And the appdelegate object is not displayed on the storyboard graph-because it should not be used to process the interface view.
  • Code writing must strictly abide by the MVC design pattern in order to use storyboard for efficient program development.

Problems in practice:

If the xcode project contains a storyboard created, it cannot be debugged and run on the simulator of IOS 4.x and the real machine of IOS 4.x. No error is reported, but only a black screen is displayed. This should be the reason why storyboard only supports ios5.

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.