AboutIPhone UIBefore development, you should pay attention to the content described in this article.IPhone UIA design suggestion. Combined with individualIPhoneDevelopment experience and points to mentionIPhone UIDevelopment suggestions.
Recommendation 1 use system controls whenever possible
System control makes it easy for users to get startedIPhoneThere are still many users who prefer to use checkbox instead of UISwitch, and use combobox instead of UIPickerView. There are two possible reasons: First, transfer from other Windows or Android systemsIPhoneThe second reason is the convergence of design to reduce design and resource work in cross-platform development. However, such a design often leads to investment in the development of custom controls, and the quality is often not comparable to that of system controls.
Suggestion 2 reasonable Abstraction
UICode is a code that is easy to repeat. In many cases, code efficiency may be wrong, which leads to the illusion of efficient work. In fact, a lot of code is completely duplicated or the structure is repeated, and can be eliminated and avoided through appropriate abstraction. For example, in an application, Web browsers embedded in different places often share some common behaviors. For example, the loading progress is displayed and the network status icon is displayed in the status bar. After loading, the progress and network status are hidden. If it is implemented separately in different controllers, it is not only unreasonable, but also may cause a large number of code duplication, which leads to a nightmare of maintenance later. Through reasonable abstraction, a base class can be extracted to encapsulate this behavior and reuse the same logic code.
Recommendation 3: Use combination first
UIMany parts should be like building blocks and can be combined at will. For example, the user information display part can be spliced by several basic controls such as UIImageView and UILabel, which are usually displayed on multiple interfaces in a project. In the face of this problem, you may want to abstract a base class to process the logic and Interface related to user information display after referring to recommendation 2. All interfaces with this requirement can inherit from this base class.
This abstraction solves the problem of repeated Implementation of logic and interface, but introduces highly coupled inheritance. If some interfaces urgently inherit one other base class for functional reasons, for example, the base class for processing webpage loading mentioned in recommendation 2, Objective-C cannot support multiple inheritance, therefore, we are forced to copy and paste part of the code. Therefore, in abstraction, we should cherish the abstract use of the base class, constantly use the Liskov principle to check and confirm the rationality of inheritance, and grasp the principle of "preferentially use combinations, use the combination of basic controls to create application-related combinations, such as displaying user information, so that other programs can reuse this part of code with combinations to avoid inheritance, other more reasonable inheritance and retention possibilities.
4. UI and logic Separation
This is very important,IPhoneThe SDK provides developers with a good foundation to separate the UI and logic. Therefore, you must follow the instructions of Apple in the implementation process, instead of mixing a large amount of logic code in the UI. In this case, I am not only sorry for the efforts of Apple engineers in this regard, but also for the endless troubles I have.
Recommendation 5 Make full use of IB.
I once met such a colleague who started to use MFC for nine years and initially hoped to use the STL library. However, after discovering the STL Memory leakage problem in a project, I developed and abandoned STL, up to now, you are not allowed to use STL in project development. This is really a snake bite, ten years of fear of the well rope. There are also people who use Xcode for iPhone development. They started to contact and use IB for a long time, but many problems and inconveniences were found during the use process, and some were even intolerable in actual projects, so that they have been in conflict with IB until now. At present, although it cannot be said that IB is already perfect, its role in improving development efficiency is beyond doubt.
Recommendation 6 do not underestimate Apple engineers
Some strange problems are often found during the development process. At this time, we usually doubt whether it is an Apple bug, So we began to look for some special processing to circumvent and gradually identify this as Apple's problem. Once you have such an experience, you will first choose the special processing you find when you encounter similar problems, and gradually deviate from the development process. For example, in order to change the color of UITableViewCell, The backgroundColor of the cell is directly changed at the beginning, but it is not fixed, after some searches, it is found that the backgroundColor of the ContenView of the cell is changed. However, once the accessoryView is displayed, the backgroundColor of the cell is displayed.
As a result, you can customize a UITableViewCell and use a UIImageView as the background. Now you can "Do whatever you want. But in retrospect, why is it really not worthwhile to make such a simple question so much, so I secretly scold Apple engineers. How can I prevent cell backgroundColor from working? This obvious bug! So that I will get used to the "soil" method in the future, and it will be difficult to try again and again. Suddenly, a similar problem was discussed on stackoverflow. The original problem can be solved by rewriting the delegate method-tableView: willDisplayCell: forRowAtIndexPath. Think about what you have said before and what you have learned. With this experience, I will doubt the rationality of using it when encountering similar problems, rather than making conclusions easily.
Summary: AboutIPhone UIYou should pay attention to the problem content before development. I hope this article will help you!