zoukankan      html  css  js  c++  java
  • NSOperationQueue 多线程

    staticNSOperationQueue * queue;

    - (void)viewDidLoad

    {

       [superviewDidLoad];

       queue = [[NSOperationQueueallocinit];

         NSInvocationOperation * op = [[NSInvocationOperationallocinitWithTarget:selfselector:@selector(download) object:nil];

        [queueaddOperation:op];

     

    }

    - (void)download {

        NSURL * url = [NSURLURLWithString:@"http://www.youdao.com"];

        NSError * error;

        NSString * data = [NSStringstringWithContentsOfURL:url encoding:NSUTF8StringEncodingerror:&error];

        if (data != nil) {

            [selfperformSelectorOnMainThread:@selector(download_completed:) withObject:data waitUntilDone:NO];

        } else {

            NSLog(@"error when download:%@", error);

            queue = nil;

        }

    }

    - (void) download_completed:(NSString *) data {

        NSLog(@"call back");

     

        self->contentLabel.text = data;

        queue = nil;

    }

  • 相关阅读:
    ExIco应用程序图标保存器1.0发布
    Object.defineProperty
    es6代理 proxy 学习
    node js学习记录
    css默认值列表
    关于 keyup keydown keypress
    转载一篇关于css选择器的,很透彻
    ......图片上传
    mimi
    css 开发心得
  • 原文地址:https://www.cnblogs.com/weiboyuan/p/3444371.html
Copyright © 2011-2022 走看看