iOS develops multi-threaded articles---communication between threads

Source: Internet
Author: User

The performance of inter-thread communication:

1 Threads pass data to another 1 threads

After performing a specific task in 1 threads, go to another 1 thread to continue the task

Here is an example of downloading a picture:

@interface  BTThreadViewController  () {    uiimageview *imagev;} @end-  (void) viewdidload{    [super viewdidload];         imagev = [[uiimageview alloc] initwithframe:cgrectmake (100, 100,  100, 100)];    [self.view addsubview:imagev];         //child thread Inside call downimage method download Picture     [self performselectorinbackground : @selector (Downimage)  withobject:nil];} -(void) downimage{    //download pictures from the network     nsurl *url = [nsurl  urlwithstring:@ "Http://i8.topit.me/8/c1/31/1142319854bdc31c18o.jpg"];    // Convert a picture to binary data     NSData *imgData = [NSData dataWithContentsOfURL:url]; Convert     //data into pictures     UIImage *img = [UIImage  Imagewithdata:imgdata];        //back to main thread settings picture     [self  Performselectoronmainthread: @selector (senderimage:)  withobject:img waituntildone:no];} -(void) Senderimage: (uiimage *) image{    imagev.image = image;}


iOS develops multi-threaded articles---communication between threads

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.