This article copies, references from the article: iOS multithreading programming nsoperation and Nsoperationqueue use, mainly in order to strengthen the personal understanding and memory of knowledge, do not do his use. Original Author statement:
Copyright statement: This article by http://blog.csdn.net/totogo2010/Original, welcome reprint share. Please respect the author Labor, reproduced when the statement and the author of the blog link, thank you!
Thanks for the hard work of the original author here!
1. There are two ways to use abstract nsoperation:
(1) Sub-classes defined with libraries: Nsinvocationoperation and Nsblockoperation.
(2) Custom class, inherit from Nsoperation. Like Java's runnable, Nsoperation is also designed to be extended by simply overriding the Nsoperation main method, which is equivalent to the Run method in Java. Then put the object of the Nsoperation subclass into the Nsoperationqueue queue, and the queue is enabled and starts processing it.
2. Example of using nsinvocationoperation: Loading pictures asynchronously
(1) Add multi-threaded calls in VIEWCONTROLLER.M:
-(void) viewdidload{ [Super Viewdidload]; // additional setup after loading the view, typically from a nib. Object : Kurl]; Nsoperationqueue* queue = [[Nsoperationqueue alloc]init]; [Queue addoperation:operation];}
The other is consistent with the Nsthread example.
3. Examples of using custom classes
Replace the Nsinvocationoperation class in 2. With the custom Nsoperation subclass, and implement the Downloadimage method in the main method in the subclass.
IOS Multithreaded Learning Note--nsoperation