Objective:
Recently written articles are entrepreneurial class, well, today write a good technical article!
But the share is not an iOS-related article, after all, these days in the crash iOS, look at the objective-c, because of the quick, very tired!
Fortunately, now basically has entered the doorway, this only to understand the new code, in order to experience the code crisis in advance.
For iOS, let's share a simple abstract package today!
1: First look at the problemDescription: Usually for the interface layout, there are writing code, XIB, storyboard three ways, and I see the new writing, is through the code layout.
The code you see is this:
A: The code that writes the UI has been detached from the new class (. h. m file), but still leaves a lot of code in Viewcontroller.
Figure 1: (After the page has been loaded, call the Setview method and then setview a bunch of UI-related code in the method)
Figure 2:
2: Think about how to optimizeGoal: Let each controller have a corresponding view of the UI class, and the controller class does not involve UI creation problems, as much as 0 intrusion.
Toss process:
These days to learn the next OBJECTC extension category category, feel this thing a bit dead end. (and the extension classes in C # are very similar, but the difference is that the object-c extension method can be transferred to the base class, which is amazing)
Unfortunately, the extension class does not support attributes, it is not able to put some variables in the extension class properties, forcing to invade the controller.
So I thought, a compromise, with generics to define a common uiview to avoid intrusion.
The result still failed, objective-c generics do not support the subclass definition type, alas ~ ~ ~
Found in C # easy to fix things, in the object-c is not easy AH!!!
3: Two tradeoff methods:
1: Define the base class for the controller, define a method, and invoke it when the page loads.
2: Suppose there is a logincontroller, create a new LoginView, inherit from UIView
3: Some UI-related definition variables are written here (. h files)
4: Add an extension class in LoginView (without creating a new class file, just append the code):
This expands a method called Initui (equals overriding the base class method)
5: This is the only one or two-time tradeoff where you need to invade Controller.h and define a UI property.
(previously wanted to define this attribute to the base class, but the generic does not support subclasses specifying the type)
6: The next step is to write your UI-related code.
Summarize:
1: Hand-written code visualization, in the debugging phase to see, this is very sad to urge the results.
2: The individual does not recommend manual layout of the Code, development efficiency is also a problem (of course, you can further improve efficiency by encapsulating some UI code).
3: Do not know that Xcode does not fold the. h file to the plugin under the. m file? Too many files, cut to cut out too hurt eyes.
Object-c iOS Pure code layout A bunch of code can be put here!