standford open course iOS7 develop Lecture10
来源:互联网 发布:使用管家婆存入软件 编辑:程序博客网 时间:2024/04/30 23:07
multithreading
技术功能:把程序要执行的任务分成多个部分,同时在处理器中执行。原因,某些任务可能会造成阻塞,如等待返回网络数据时。
in iOS 由queue 来实现,不同queue中的代码块,block,排队等待被执行。serial queue 串行队列,还有concurrent queue并行队列。
Main queue 监听用户,同步UI,不希望被阻塞。会在安静一会儿之后再执行其他的block
Demo: download the contents of an url
UIScrollview: 里面的内容可以滚动,放大,缩小。以放下更多的内容。
Create: Drag it. But put the subviews by code。
Demo在其他队列下载图片,完成后通知主队列,并显示在imageView里面。在执行下载过程中,需要时间,执行完成后,要检查一下是否依然满足开始执行它的要求。
1. 在一个在运行时会被调用的方法中,依次创建一个NSURLRequest *request, NSURLSessionConfiguration *configuration, NSURLSession *session, NSURLSessionDownloadTask *task, 然后执行[task resume]
-(void)startDownloadingImage{ self.image = nil; if (self.imageURL) { NSURLRequest *request = [[NSURLRequest alloc] initWithURL:self.imageURL]; NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *localfile, NSURLResponse *response, NSError *error) { if (!error) { if ([self.imageURL isEqual:request.URL]) { UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:localfile]]; [self performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO];// dispatch_async(dispatch_get_main_queue(), ^{ self.image = image; }); //Totally C的方法also can work } } }]; [task resume]; }}
0 0
- standford open course iOS7 develop Lecture10
- Standford NLP Course(2) - Edit Distance
- Standford NLP Course(3) - Language Modeling
- Open Course
- standford iOS7 公开课笔记目录树
- standford iOS7 公开课笔记目录树
- Standford NLP Course(1) - Introduction & Basic Text Process
- 几个很好的 Open Course
- Massive Open Online Course(MOOC)
- open course link 公开课资源链接
- #develop
- lecture10,Recurrent Neural Network
- Google to Android Developers: 'Do Not Develop in the Open'
- Course
- course
- 金融市场:Open.Yale.course--Financial.Markets.03.Chi_Eng.
- 金融市场:Open.Yale.course:Financial.Markets.07.Chi_Eng
- Unit 2-Lecture10: Forests & Tree
- 【索引】String
- c语言
- 【九度OJ】1028【快排】【kruskal】【畅通工程系列2008】
- 实习的第一个月
- 【索引】Big Number
- standford open course iOS7 develop Lecture10
- jsp传参到servlet中文乱码处理
- 【索引】Sorting/Searching
- HDU1233
- apache错误:Internal Server Error
- poj1028~无聊但是慢慢增加信心的水题
- poj 2155 二维BIT
- 显式调用构造函数时不能引用实例字段请解释为什么“显式调用构造函数时不能引用实例字段”
- 2014.08.21 周五-sql语句-web:虚拟主机-IE与服务器交互-打包war-密码学-tomcat的管理平台