SB in iOS and Xib's past life

Source: Internet
Author: User

Today, let's introduce three kinds of commonly used application writing methods in Apple development: pure code creation, using Storyboard/xib. as we all know, the code-writing mode is suitable for large-scale projects, and it is good for versioning, tracking and code merging , code reusability, and quick maintenance of code later. but we can not deny its long development cycle, code structure complex, automatic layout autolayout difficulties and other shortcomings,

First, Interface Builder introduction

1. Concept

Interface Builder Apple Platform for designing and testing user interface applications, referred to as IB. Simply understood, IB is a visual design environment.

Interface Builder , is for Apple Inc. Mac OS X the Software development Program of the operating system, Xcode part of the kit

Interface Builde: A tool for visualizing the creation of interface profiles, open xib to see the file structure of XML

xcode.3.0 before the Interface build file is a binary nib nib that represents next Interface builder because nib is binary poorly managed and inconvenient to version control xcode.3.0 Interface Builder A new file format is used xib xib means XML Interface Builder, Xib uses XML to convert to nib when the project is compiled

Before Xcode 4.0 interface Builde was a standalone software, and Xcode 4.0 was a large version of the interface was redesigned interface Builder was directly integrated into Xcode

Note: When we use Xib to encounter Xib added to the controller view, sometimes the program crashes.

Error tip: Unrecognized selector sent to instance 0x7ffae1c1b680 '

At this point we should note that there are several controls in the Xib, and we load the Xib as an array Xib objects are arranged in the order in which they are entered.

2. Function and characteristics

IB provides users with a visual interface, which makes it easy and intuitive to design user interface elements. The drag-and-drop panel from IB provides a convenient and easy-to-use interface for building a UI. Using IB is optional, because all controls can be implemented using code.

3. Integration

The Interface Builder tool is available in the iphone SDK for Mac OC and iOS app development, starting with XCODE4 and integrating into it (previously standalone software).

4. NIB Element

(1) The nib file is a resource document that holds the relationships between objects and objects created by Interface Builder, and the nib is the abbreviation for NeXT Interface Builder.

(2) Earlier, IB used nib files to store control resources, and the nib itself was a binary file.

5, the emergence of xib

(1) Since Xcode 3.0, Apple has provided xib files to build UI elements that are essentially XML text files that can be easily edited. At the same time Xib can be compiled to nib.

(2) Nib and Xib are Interface Builder's graphical interface design documents.

Ii. introduction of Xib

1. Introduction

(1) IB and Xib are bundled in the Developer Toolkit from the first launch of the iOS SDK (standalone), and have been integrated directly into Xcode after Xcode 4 as part of the IDE.

(2) Xib is a file in XML format.

(3) before theUiviewcontroller life cycle function loadview ,Xib will be converted into an executable nib File

1. function

(1) Loading controls via Xib

<1>loadnibnamed method

(2) Load controller via Xib

<1>initwithnibname:bundle: Method (if Xib and controller name are the same or approximate, you can not instantiate)

<2> setting associations in the identity inspector for Xib

<3> set file ' s Owner, drag onto view

3. Advantages

(1) compared to pure code, greatly shorten the time of the UI interface construction, improve the development efficiency.

(2) Visualization of the effect, more intuitive design

(3) The differences in version management and pure code are not very large, easy to read and easy to maintain.

4. Questions

(1) Xib cannot make logical judgments.

(2) Difficult to configure at runtime, xib in use, often through the code to complement the implementation of the function.

(3) In multi-person development, modifying the properties of Xib by code can cause confusion and unpredictable problems.

(4) from the programmer's point of view, poor readability. Not conducive to unified management and maintenance. When using code management tools such as SVN, Xib generates useless records, as well as defects in version updates. Starting with XCODE5, Apple has optimized this aspect of the problem, such as versioning, and finding changes to the record.

(5) settings in Xib are often not final andUI design is overwritten by code

(if you choose xib, try to isolate the work of Xib from the work of your code: You can use the xib The finished content is unified using xib To do, not say three labels Two of them in xib The font is set and the other is done in the code. It would be a good way to try to keep only the necessary, less iboutlet and ibaction. )

6. Several methods related to Xib

(1) loadNibNamed:owner:options Loading Xib controls

(2) Aweakfromnib This method in the associated class is called by the Xib load control

(3) Initwithcoder This method in the associated class is called by the Xib load control

Third, StoryBoard

1. Introduction

iOS5 after version , The Apple Company launched Storyboard, The new project is currently created with the default self - Storyboard, can say StoryBoard is the trend of the future .

1. What is storyboard?

What we can literally understand as storyboards storyboard is that the new features of IOS5 are designed to replace the historic xib

Storyboard is a description file for multiple Xib file collections, also in XML format

If you want to use the storyboard attribute, then appdelegate must inherit from the Uiresponder class, previously inherited from the NSObject class, and must have a window property declaration that is not a uioutlet class to

Note: When we need to change stoard we need to remove infor.plist Main interface, otherwise it will be an error.

2. Features

(1) To provide a new way of challenge between pages: Segue

(2) Describes some key information such as forms, components, Auto Layout constraints, and so on.

(3) default storyboard as the main entrance of the program

(4) Auto Layout with StoryBoard, can greatly improve the efficiency of UI development, and accurately provide the location and constraints of each control.

(5) The relationship between the controller is shown in the storyboard.

3. Advantages

(1) storyboard introduced in IOS5, is the Xib collection of the description file, itself is an XML format, provides the NIB and xib centralized management, more intuitive to show their relationship.

(2) To improve the efficiency of UI design, through the visual interface, can clearly reflect the relationship between the controller jump.

(3) in the storyboard can provide a simple page jump, drag and drop can be set to success.

(4) The UI design can reflect the design effect in real time, because of the small amount of code, so the probability of the bug is also low (Code implementation UI requires a lot of code).

(6) Low Code volume, short development cycle

(7) is the default configuration for new projects, which means that the future direction and center of gravity of Apple will tend to visualize programming.

4. Use

(1) Load Controller via storyboard

<1> Create Uistoryboard object: Storyboardwithname:

<2> Created with storyboard objects

Instantiateinitialviewcontroller;

Instantiateviewcontrollerwithidentifier;

(2) Load view via storyboard,

<1> set the style, and reusedid, in prototype cells to enable cell reuse.

The item registration in <2> collection is also available through prototype cells

5. Questions

(1) There are some problems in the design of xib, such as inconvenient maintenance, inconvenient development of many people, no logic judgment and so on.

(2) The biggest problem is the collaborative development of multiple people, and the UI controls are in one storyboard file.

(3) because it is multiple xib, more will be larger, loading will be slower.

(4) The reuse problem is inflexible because no code design controls are used.

Iv. the difference between Xib and Storyboard

Common denominator: All interfaces used to describe the software are compiled with the interface Buile tool

Different points: (1) Xib is lightweight to describe the local UI interface, while storyboard is a heavyweight used to describe the entire software interface and can show a jump relationship between multiple interfaces

(2) Storyboard is a description file for multiple Xib file collections, also in XML format. There can be multiple xib files in a project, and a xib file corresponds to a view controller and multiple views. When using storyboard, a project requires only one master storyboard file. Therefore, in the case of multiple view controllers, it is convenient to use storyboard management, and storyboard can also describe the navigation relationship between interfaces.

Five, the use of storyboard points of attention.

The use of storyboard should be noted:

1. If you want to use the storyboard attribute, then appdelegate must inherit from the Uiresponder class, which is inherited from the NSObject class, and must have a window property declaration that is not a uioutlet class to

2, Storyboard proprietary preview function, as well as the function of AutoLayout.

3, the existence of a single view is not allowed in storyboard

The use of Xib and storyboard is briefly described in this paper.

Xib Use process:

1. First Use interface Builder to create a new UIView. xib file.

2. Add the required controls to the newly created. xib file of the UIView.

3. Define a derived class that inherits from UIView. Change the derived class of the newly created Xib file above to a newly defined derived class that inherits from UIView.

4. Connect the control added on the Xib file to a derived class that inherits from UIView Ibooutlet.

5. Add the code where you need to generate UIView:

nsarray* Nibview = [[Nsbundlemainbundle] loadnibnamed:@ "xib file name" Owner:nil Options:nil];

UIView * Backupsearchview = [Nibview lastobject];

Storyboard Use process:

1. Create a window

Self.window = [[UIWindow alloc] Initwithframe:[uiscreen mainscreen].bounds];

2. Create a controller [storyboard storyboard]

2.1 Loading the storyboard file first

Uistoryboard *boss = [Uistoryboard storyboardwithname:@ "Czboss" bundle:nil];

2.2 Instantiating the initialization controller [with arrows]

Uiviewcontroller *VC = [boss Instantiateinitialviewcontroller];

Instantiate the controller according to the representation

Uiviewcontroller *VC = [boss instantiateviewcontrollerwithidentifier:@ "Blue"];

3. Setting the root controller of the window

Self.window.rootViewController = VC;

4. Use the window as the main window and visible

[Self.window makekeyandvisible];

Reference: http://news.cnblogs.com/n/124292/

SB in iOS and Xib's past life

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.