• 线程与下载


    #pragma mark 创建新线程3
    - (void)createThread3 {
        // 隐式创建一个新线程执行self的run:方法
        // 创建完毕后马上启动线程
        [self performSelectorInBackground:@selector(run:) withObject:@"mj"];
    }

    #pragma mark 创建新线程2
    - (void)createThread2 {
       
    // 隐式创建一个新线程执行self的run:方法
        // 创建完毕后马上启动线程
        [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"mj"];
    }

    #pragma mark 创建新线程
    - (void)createThread {
        NSThread *thread = [[[NSThread alloc] initWithTarget:self selector:@selector(run:) object:@"mj"] autorelease];
        NSLog(@"thread-%@", thread);
        // 启动线程
        [thread start];
    }

    #pragma mark 下载图片
    - (void)download {
        [self performSelectorInBackground:@selector(downloadImage) withObject:nil];
    }

    #pragma mark 在后台线程下载图片
    - (void)downloadImage {
        NSLog(@"%@", [NSThread currentThread]);
        
        NSString *url = @"http://f.hiphotos.baidu.com/album/w%3D2048/sign=f2f363781e30e924cfa49b3178306f06/9922720e0cf3d7ca8e304106f31fbe096a63a9f8.jpg";
        
        NSURL *URL = [NSURL URLWithString:url];
        NSData *data = [NSData dataWithContentsOfURL:URL];
        UIImage *image = [UIImage imageWithData:data];
        
        // 在主线程调用self.imageView的setImage:方法
        [self.imageView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:YES];
    }

     
  • 相关阅读:
    【原创】性能测试之——网络环境分析
    【转载】测试人员管理之——离职类型分析
    【转载】测试人员管理之——离职人员管理
    【转载】测试缺陷生命周期定义
    【转载】如何对软件测试方法分类
    【原创】Java批量反编译利器(jd-gui)介绍
    【原创】Linux常用管理命令总结
    shelve模块 xml模块
    json模块
    sys模块
  • 原文地址:https://www.cnblogs.com/wangshengl9263/p/3053311.html
Copyright © 2020-2023  润新知