1. It is better to have a class that inherits from uiviewcontroller in project creation, and other controllers inherit from this controller, which is more flexible. For example:
You need to add or add user operation track records to each page of the Project, which saves the trouble of adding each page. You can write the logic in this parent class!
2. You don't need to use all the UI elements in the Controller. Self. View addsubview. It's really dizzy to write more. The logic and try to join! Add the custom View class to the Controller.
3, the execution of network request asynchronous task too much will consume resources, it is best to use the queue reference: http://blog.csdn.net/totogo2010/article/details/8013316
This section describes the methods used in professional projects.
Structure:
1 class that inherits nsoperation myoperation
One management class that inherits nsobject, for example, TASKMANAGER
Nsoperation is similar to the java. Lang. runnable interface. Like java's runnable, nsoperation is also designed for extension. You only need to inherit the main method of rewriting nsoperation. It is equivalent to the run method of runnalbe in Java. Then, put the nsoperation subclass object into the nsoperationqueue queue, and the queue starts and starts to process it.
// Task execution class
@ Interface myoperation: nsoperation
@ Implementation myoperation
// Reload the parent class method, and the queue automatically executes the main
-(Void) Main {
@ Autoreleasepool {
@ Try {
// Main code
Nslog (@ "++ + ============================= ");
} @ Catch (nsexception * E ){
// Exception Handling
} @ Finally {
// Generally, no code is written.
}
}
}
@ End
/// // Manage the class of the task to be executed
# Import "myoperation. H"
// Simple test here, without writing a singleton
@ Interface taskmanager: nsobject
{
// Create a task queue
Nsoperationqueue * operationqueue;
}
-(Void) startoperation;
@ End
-(Instancetype) Init
{
Self = [Super init];
If (Self ){
Operationqueue = [[nsoperationqueue alloc] init];
// The number of tasks executed at the same time, mainly for its purpose
Operationqueue. maxconcurrentoperationcount = 1;
}
Return self;
}
-(Void) startoperation
{
Myoperation * op = [[myoperation alloc] init];
[Operationqueue addoperation: op];
}
// Call at usage
Taskmanager * manager = [[taskmanager alloc] init];
[Manager startoperation];
(Work Experience Summary: 1) queue-reasons for multiple main