Multi-thread programming in Ios development-NSThread and iosnsthread
The IOS program updates the UI view and responds to the screen touch event through the main thread during running. However, there will be some time-consuming work during view update, in this case, the system gets stuck. This is caused by the blockage of the main thread. This will make the user experience very poor!
To solve this problem, we can use multi-threaded programming to put some time-consuming work in other threads outside of the thread to solve the problem and increase the running efficiency!
Let's talk about how to enable the thread using NSThread;
We can use the NSThread class to enable threads. An NSThread instance object is a thread.
I. NSThread Creation
Object method:
Class method:
Both methods have three parameters:
Selector: method to be executed by the thread
Target: the object of the execution method.
Argument: method parameter. Only one object parameter can be passed.
Ii. Obtain the current thread
NSThread * thread = [NSThread currentThread];
3. Return to the main thread
Iv. Example
NSThread:
5. The result is as follows:
Author: Jerry Education
Source: http://www.cnblogs.com/jerehedu/
Copyright Disclaimer: The copyright of this article is shared by Yantai jereh Education Technology Co., Ltd. and the blog Park. You are welcome to repost it. However, you must keep this statement without the consent of the author and provide the original article connection clearly on the article page, otherwise, you are entitled to pursue legal liability.
Technical Consultation: