Multi-thread programming in Ios development-NSThread and iosnsthread

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.