How to Develop view

Source: Internet
Author: User

In the process of developing the view will certainly encounter in the end is the use of pure code or Xib or storyboard, this is an experience, not a certain experience of the person can not be seen at the first sight, even if the first can be seen in the later maintenance will also exist more or less problems, So my idea is that unless there are some things that are impossible to change, such as logging in, registering, and so on, or a few controls, it is very flexible to use with xib, and all other parts should be xib pure code. Although the pure code in the process of writing, will feel very troublesome, but this is a cumulative process, after you have some experience, you may fall in love with it maybe, because it is a lot less trouble xib.

Xibs

By using IB and Xib files to organize the UI relative to the code, you can save a lot of code and time for faster development. If you have ever been poisoned and maimed by the visual interface of the Microsoft home Visual Basic or other visual system, and therefore suspect interface Builder's pure pedigree and ability to work, it is recommended to take a look at these materials to correct the three views: Jean-marie Hullot's Interface builder myth, the green amid of a suit and suit, will build the app with IB at next (FQ required). Alternatively, you might want to open the application folder on your Mac or the Apple Home app on your iphone. You will be surprised to find that IB is far more powerful than you can see: small tools such as the Calculator picker, up to iwork three-piece set, aperture or final cut for professional applications, none of which is done using IB for UI production.

In fact, IB and Xib are bundled in the Developer Toolkit from the first launch of the iOS SDK, and have been integrated directly into Xcode after Xcode 4 as part of the IDE. One of the main purposes of xib design is good MVC: In general, a single xib file corresponds to a viewcontroller, and for some custom view, it is often loaded using a single xib and loading from the main bundle. IB helps with the creation of view, layout, and relational mapping with file owner, among other things. For beginners, keep in mind that xib files are the content of the view, help to build a better concept of MVC, so that in the development of avoid or less detours.

Xib file before a big problem is that the file content is too complex, the readability is poor, even if simply open without editing can cause changes and cause the suffering of merging and submitting. In Xcode 5, Apple dramatically simplifies the format of the Xib file, making it easy to read and maintain. Can say now for the Xib file in version management and pure code is not much different, as long as carefully read the Xib file content, naturally can understand the vast majority of, and well track and find the past changes record.

Of course xib is not perfect either. The biggest problem is that the settings in Xib are often not final, and in the code you will have the opportunity to overwrite the UI design you made in the Xib file. Setting the same property in different places will be a nightmare in later maintenance. Because IB is still limited, it has no logical judgment, and it is difficult to configure at runtime, whereas the use of code is indeed omnipotent. When using Xib, it is almost inevitable to complement and complete functionality with part of the code. On this point in the development should be highly valued, if you choose Xib, then try to isolate the work of xib and the work of the code: the ability to use Xib to complete the content of the unified use of xib to do, not to say three labels two of them in the Xib set the font and the other is in the code to complete. It would be a good way to try to keep only the necessary, less iboutlet and ibaction.

StoryBoard

After IOS5, Apple provides a new way to make the UI, which is storyboard. Simply understood, storyboard can be seen as a set of Viewcontroller corresponding Xib, and the way in which they are transformed. In storyboard, you can see not only the layout style of each viewcontroller, but also the conversion relationship between each viewcontroller. Compared with the individual xib, the code needs less, and because of the aggregation of the various xib, the speed of understanding and modifying the interface is improved greatly. Reducing the amount of code means reducing the amount of bugs, which is one of the truths in program development.

After Xcode5, Storyboard has become the default configuration for new projects, which also represents Apple's advice and future direction for developers. WWDC2013 's various Sample code also basically used storyboard to demonstrate. As you can foresee, Apple will certainly continue to strengthen in this area, and conversely, pure code or a single xib will probably not be enhanced.

If you don't consider iOS version support (in fact, it's very rare to see apps that you want to start supporting from IOS4), now the biggest problem for storyboard is collaborating with multiple people. Because all the UI is defined in a file, many developers personally or the company's technical leaders believe that storyboard is not able to collaborate on development, in fact, this is more a kind of storyboard of the unfamiliar caused by misunderstanding. Although Apple does not explicitly mention it in WWDC, no one is required to have only one storyboard file for the entire project. One possible approach is to break down different parts of the project into several storyboard and arrange for developers to be responsible for their own parts. For example, a Uitabbarviewcontroller-based application with 4 tab functions that is independent of each other, can use 4 storyboard to represent 4 tabs, and develop without interfering with each other. So there is no such thing as a conflict. Storyboard API is so simple, now the total number of methods in the SDK a hand can be counted, so the specific method here is no longer wordy.

Another challenge for storyboard comes from the reuse of Viewcontroller and the processing of custom view. For the former, in the correct packaging interface and good design on the basis, in fact, storyboard VC reuse and code VC reuse is no essential difference, in the storyboard to add a good package needs to be reused scene can be resolved. For the latter, because the existence of a single view is not allowed in storyboard, many times we still need to customize the UI with the help of a single xib. This is due to the storyboard design ideas, storyboard more emphasis is a hierarchy, is a global perspective on the organization of UI design and migration. For a single view, more attention is paid to reuse and customization than to the entire project's process. I believe that by seizing this point, you will be well aware of when to use Xib and when to use storyboard.

The last word about storyboard is that there are now some concerns about storyboard performance. Because storyboard files tend to be larger and load slower relative to a single xib. But in fact, with the current equipment replacement, in the iPhone4 are difficult to find today, this performance gap can almost be ignored. And then the device, whether read or parse, will only get faster and quicker. So the problem of performance is absolutely not necessary to worry about.

How to Develop view

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.