zoukankan      html  css  js  c++  java
  • 第一篇:线程间的通信

     

    1.线程间的通信:在一个进程中,线程往往不是独立存在的,多个线程之间需要经常进行通信。

    2.线程间通信的体现:

       一个线程传递数据给另一个线程

      在一个线程执行完特定任务后,转到另一个线程继续执行任务

    3.线程间通信常用方法:

    —(void)performSelectorOnMainThread:(SEL)aselector  withObject:(id)arg waitUntilDone:(BOOL)wait;

    —(void)performSelector:(SEL)aselector onThread:(NSTread*)thr WithObject:(id)arg waitUntilDone:(BOOL)wait;

    4.我们就用图表做示例:

    5.代码如下:

    #import "ViewController.h"

    @interface ViewController ()

    @property(nonatomic,strong)UIButton*button;

    @end

     

    @implementation ViewController

     

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor=[UIColor whiteColor];

        [self UIButton];

       

    }

    -(void)UIButton{

        self.button=[[UIButton alloc]initWithFrame:CGRectMake(130, 50, 100, 50)];

        self.button.backgroundColor=[UIColor blueColor];

        [self.button addTarget:self action:@selector(download) forControlEvents:UIControlEventTouchUpInside ];

        [self.view addSubview:_button];

    }

    -(void)download{

        //1.根据url下载图片

        //从网络下载图片

        NSURL * url = [NSURL URLWithString:@"http://img3.cache.netease.com/3g/2015/9/29/20150929110202279dd.png"];

        

        

        //把图片转化为二进制

        NSData*data = [NSData dataWithContentsOfURL:url];

        

        //把数据转化成图片

        UIImageView*image=[[UIImageView alloc]initWithFrame:CGRectMake(100, 300, 100, 80)];

        image.image=[UIImage imageWithData:data];

    }

     

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

     

    @end

  • 相关阅读:
    Maven 入门 (1)—— 安装
    centos下保留python2安装python3
    chrome各版本下载
    nginx 图片访问404 (使用location中使用 root,alias的区别)
    centos7无GUI运行selenium chromedriver 亲测可用!
    常用xpath选择器和css选择器总结
    在flask中使用swagger(flasgger使用方法及效果展示)
    判断回文字符串、回文链表、回文数(python实现)
    (9) MySQL主主复制架构使用方法
    (10) 如何MySQL读压力大的问题
  • 原文地址:https://www.cnblogs.com/jinchengvs/p/4846371.html
Copyright © 2011-2022 走看看