staticNSOperationQueue * queue;

- (void)viewDidLoad

{

  [superviewDidLoad];

  queue = [[NSOperationQueuealloc] init];

 NSInvocationOperation * op = [[NSInvocationOperationalloc] initWithTarget: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;

}

NSOperationQueue 多线程的更多相关文章

  1. 多线程下NSOperation、NSBlockOperation、NSInvocationOperation、NSOperationQueue的使用

    本篇文章主要介绍下多线程下NSOperation.NSBlockOperation.NSInvocationOperation.NSOperationQueue的使用,列举几个简单的例子. 默认情况下 ...

  2. IOS 多线程02-pthread 、 NSThread 、GCD 、NSOperationQueue、NSRunLoop

    注:本人是翻译过来,并且加上本人的一点见解. 要点: 1.前言 2.pthread 3.NSThread 4.Grand Central Dispatch(GCD) 5.Operation Queue ...

  3. iOS多线程-03-NSOperation与NSOperationQueue

    简介 通过NSOperation与NSOperationQueue的组合也能实现多线程 通常将任务封装成NSOperation对象,并将对象添加到NSOperationQueue中实现 NSOpera ...

  4. IOS多线程(NSOperation,NSOperationQueue)

    含义:NSOperation,NSOperationQueue是什么. The NSOperation class is an abstract class you use to encapsulat ...

  5. 用NSOperation和NSOperationQueue实现多线程编程

    1.上一讲简单介绍了NSThread的使用,虽然也可以实现多线程编程,但是需要我们去管理线程的生命周期,还要考虑线程同步.加锁问题,造成一些性能上的开销.我们也可以配合使用NSOperation和NS ...

  6. 多线程下的NSOperation和NSOperationQueue的使用

    多线程下的NSOperation和NSOperationQueue的使用 NSOperation和NSOperationQueue的介绍: NSOperation是Cocoa中的一个抽象类,用来封装单 ...

  7. [转] iOS多线程编程之NSOperation和NSOperationQueue的使用

    <iOS多线程编程之NSThread的使用> 介绍三种多线程编程和NSThread的使用,这篇介绍NSOperation的使用. 使用 NSOperation的方式有两种, 一种是用定义好 ...

  8. Swift - 多线程实现方式(2) - NSOperation和NSOperationQueue

    1,Swift继续使用Object-C原有的一套线程,包括三种多线程编程技术: (1)NSThread (2)Cocoa NSOperation(NSOperation和NSOperationQueu ...

  9. [ios2]使用NSOperationQueue简化多线程开发和队列的优先级 【转】

    多线程开发是一件需要特别精心的事情,即使是对有多年开发经验的工程师来说. 为了能让初级开发工程师也能使用多线程,同时还要简化复杂性.各种编程工具提供了各自的办法.对于iOS来说,建议在尽可能的情况下避 ...

随机推荐

  1. MySQL添加字段和修改字段的方法

    添加表字段 alter table table1 add transactor varchar(10) not Null; alter table   table1 add id int unsign ...

  2. 点击repeater的一个修改事件触发全部repeater每一行的修改事件

    <td align="center">                            <asp:LinkButton ID ="btnvip&q ...

  3. 循环repeater中的每一列,并计算数据和

    <asp:Repeater ID="rpt" runat="server"> <ItemTemplate> <td>< ...

  4. c++模版函数

    1.定义 可以使用class或者typename字段来申明 template <class T> template <class T1, class T2, ...class TN& ...

  5. kvm快照

    Kvm快照: 1.基于lvm的快照 2.kvm自带的快照功能(需要qcow2 磁盘文件才支持快照) 关闭kvm虚拟机: 查看磁盘文件信息: [root@super67 ~]# qemu-img inf ...

  6. hdu 猜数字

    这题的意思是找到最大的n使得m次之内的猜测可以猜到1~n之间的任何值.这里是二分思想的逆过程,1~h个数最多猜测log2(n+1)次(n为奇数),故 n=2^m-1; #include"io ...

  7. PHP json_decode 函数解析 json 结果为 NULL 的解决方法

    在做网站 CMS 模块时,对于模块内容 content 字段,保存的是 json 格式的字符串,所以在后台进行模块内容的编辑操作 ( 取出保存的数据 ) 时,需要用到 json_decode() 函数 ...

  8. Socket简介

    本文全部摘抄http://c.biancheng.net/cpp/html/3029.html 大多数项目是在Linux下开发服务器端,而在Windows下开发客户端,需要经常在两大平台之间进行切换, ...

  9. 20145235 《Java程序设计》第9周学习总结

    第十六章 整合数据库 JDBC Java语言访问数据库的一种规范,是一套API. JDBC (Java Database Connectivity) API,即Java数据库编程接口,是一组标准的Ja ...

  10. [转]LaTeX处女级入门命令语法集

    1.LaTeX文件的框架如下: \documentclass{article} \begin{document} This is the body of the article \end{docume ...