NSOperationQueue 多线程
2013-11-26 21:51
267 查看
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;
}
- (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;
}
相关文章推荐
- ios UI
- iOS 获取UUID
- 关于QueryParser类前后修改
- 敏捷爽畅(Agile Fluency)之道
- 【iOS】UILabel自适应高度和自动换行
- 【索引】 Volume 7. Graph Algorithms and Implementation Techniques
- STL中stack,queue的操作
- 基于MVC4+EasyUI的Web开发框架形成之旅--界面控件的使用
- 获取ADOQuery结果集的值
- CoreData之FetchRequestController
- iphone UIImage用法介绍
- UIScrollView 类负责所有基于 UIKit 的滚动操作
- TI CC2540/2541 Bluetooth Low Energy Software Developer's Guide第三章
- 利用requestAnimationFrame实现智能动画
- apue 1 课后习题
- CodeForces 366 E. Dima and Magic Guitar
- Using UIPageControl as a container UIViewController
- Codeforces round 146 C - Cyclical Quest(后缀自动机)
- Request.Url.Port 获取不到正确的端口号
- 如何在网页中使用媒体查询 media queries