NSOperationQueue 多线程
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 多线程的更多相关文章
- 多线程下NSOperation、NSBlockOperation、NSInvocationOperation、NSOperationQueue的使用
本篇文章主要介绍下多线程下NSOperation.NSBlockOperation.NSInvocationOperation.NSOperationQueue的使用,列举几个简单的例子. 默认情况下 ...
- IOS 多线程02-pthread 、 NSThread 、GCD 、NSOperationQueue、NSRunLoop
注:本人是翻译过来,并且加上本人的一点见解. 要点: 1.前言 2.pthread 3.NSThread 4.Grand Central Dispatch(GCD) 5.Operation Queue ...
- iOS多线程-03-NSOperation与NSOperationQueue
简介 通过NSOperation与NSOperationQueue的组合也能实现多线程 通常将任务封装成NSOperation对象,并将对象添加到NSOperationQueue中实现 NSOpera ...
- IOS多线程(NSOperation,NSOperationQueue)
含义:NSOperation,NSOperationQueue是什么. The NSOperation class is an abstract class you use to encapsulat ...
- 用NSOperation和NSOperationQueue实现多线程编程
1.上一讲简单介绍了NSThread的使用,虽然也可以实现多线程编程,但是需要我们去管理线程的生命周期,还要考虑线程同步.加锁问题,造成一些性能上的开销.我们也可以配合使用NSOperation和NS ...
- 多线程下的NSOperation和NSOperationQueue的使用
多线程下的NSOperation和NSOperationQueue的使用 NSOperation和NSOperationQueue的介绍: NSOperation是Cocoa中的一个抽象类,用来封装单 ...
- [转] iOS多线程编程之NSOperation和NSOperationQueue的使用
<iOS多线程编程之NSThread的使用> 介绍三种多线程编程和NSThread的使用,这篇介绍NSOperation的使用. 使用 NSOperation的方式有两种, 一种是用定义好 ...
- Swift - 多线程实现方式(2) - NSOperation和NSOperationQueue
1,Swift继续使用Object-C原有的一套线程,包括三种多线程编程技术: (1)NSThread (2)Cocoa NSOperation(NSOperation和NSOperationQueu ...
- [ios2]使用NSOperationQueue简化多线程开发和队列的优先级 【转】
多线程开发是一件需要特别精心的事情,即使是对有多年开发经验的工程师来说. 为了能让初级开发工程师也能使用多线程,同时还要简化复杂性.各种编程工具提供了各自的办法.对于iOS来说,建议在尽可能的情况下避 ...
随机推荐
- 静态页分页功能js代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- VTKMY 3.3 VS 2010 Configuration 配置
Download VTKMY 3.3 Download VS2010 Download CMake 3.2.0 I assume you've already installed VS2010 and ...
- hdu Collect More Jewels
思路: 先用bfs求出入口,宝物,出口,两两之间的最短距离. 在用dfs搜索所有情况,求出从入口走到出口能获得的最大价值. 我们要解决几个问题:1.求入口到第一个取宝物的地方的最短距离 2.求第i个取 ...
- 批量硬关联本地AD帐号与Office云端帐号
世纪互联给的方案, 说只能一个一个做硬匹配, 把我吓尿了. 我整个简单的, 还能批量做. 1. 将本地域中所有用户的这两个属性导出. Get-ADUser -Filter * -SearchBase ...
- 如何用Apache POI操作Excel文件-----如何对一个单元格加注解?
有的时候,我们需要通过操作Apache POI,在生成Cell数据的同时,能对其生成的Cell,加上注解(comments),类似于下面的. 那么对于这种情况,我们的代码应该如何写呢? 借花献佛,我就 ...
- charles 常用设置
一.过滤网络请求 通常情况下,我们需要对网络请求进行过滤,只监控向指定目录服务器上发送的请求.对于这种需求,我们有2种办法. 1.在主界面的中部的Filter栏中填入需要过滤出来的关键字.例如我们的服 ...
- linux常用命令的英文单词缩写
命令缩写: ls:list(列出目录内容) cd:Change Directory(改变目录) su:switch user 切换用户rpm:redhat package manager 红帽子打包管 ...
- DataSet key points
In a typical multiple-tier implementation, the steps for creating and refreshing a DataSet, and in t ...
- Cacti安装详细步骤
原文链接: https://www.centos.bz/2012/01/cacti-install-tutorials/ Cacti-监控MySQL: http://www.cszhi.com/201 ...
- js 键盘移动div、img对象
js 键盘移动div.img对象 <html> <script type="text/javascript"> var EXtype="" ...