IOS第二天多线程-01-延时执行
**********延时执行
#import "HMViewController.h" @interface HMViewController () @end @implementation HMViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
} - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"-----touchesBegan1-----"); NSLog(@"-----touchesBegan2-----");
} - (void)download:(NSString *)url
{
NSLog(@"download------%@---%@", url, [NSThread currentThread]);
} - (void)delay3
{
// 3秒后回到主线程执行block中的代码
// dispatch_queue_t queue = dispatch_get_main_queue();
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), queue, ^{
// NSLog(@"------task------%@", [NSThread currentThread]);
// }); // 3秒后自动开启新线程 执行block中的代码
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, );
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)( * NSEC_PER_SEC)), queue, ^{
NSLog(@"------task------%@", [NSThread currentThread]);
});
} - (void)delay2
{
// 一旦定制好延迟任务后,不会卡主当前线程
[self performSelector:@selector(download:) withObject:@"http://555.jpg" afterDelay:];
} - (void)delay1
{
// 延迟执行不要用sleep,坏处:卡住当前线程
[NSThread sleepForTimeInterval:];
NSLog(@"-----下载图片-----");
} @end
IOS第二天多线程-01-延时执行的更多相关文章
- IOS第二天多线程-05NSOperationQueue 暂停,和恢复队列任务
*********** #import "HMViewController.h" @interface HMViewController () <UITableViewDel ...
- IOS第二天多线程-03对列组合并图片
********* // 2D绘图 Quartz2D // 合并图片 -- 水印 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *) ...
- IOS第二天多线程-02一次性代码
********** #import "HMViewController.h" #import "HMImageDownloader.h" @interface ...
- iOS常见的几种延时执行的方法
1.performSelector [self performSelector:@selector(delayMethod) withObject:nil/*可传任意类型参数*/ afterDelay ...
- IOS第二天多线程-04简化单例模式
******HMSingleton-ARC.h // .h文件 #define HMSingletonH(name) + (instancetype)shared##name; // .m文件 #de ...
- iOS:延时执行的三种方式
延时执行的三种方式:performSelectorXXX方法.GCD中延时函数.创建定时器 第一种方式:NSObject分类当中的方法,延迟一段时间调用某一个方法 @interface NSObj ...
- iOS中延时执行的几种方式的比较和汇总
本文列举了四种延时执行某函数的方法及其一些区别.假如延时1秒时间执行下面的方法. - (void)delayMethod { NSLog(@"execute"); } 1.perf ...
- IOS中延时执行的几种方式的比较
本文列举了四种延时执行某函数的方法及其一些区别.假如延时1秒时间执行下面的方法. - (void)delayMethod { NSLog(@"execute"); } 1.perf ...
- iOS延时执行的四种方法
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
随机推荐
- [HTTP那些事]网络请求API
在Android上,原生API有两个,HttpUrlConnection和HttpClient,它们对封装Socket进行封装,让HTTP请求变得简单.这应该也算框架吧? 想象下,如果没有HttpUr ...
- 《DSP using MATLAB》示例Example4.7
ROC分三种情况:
- 配置.net连接数据库的配置文件
今天调试一个学生信息管理系统时,启动系统之后,登录时老是报错说实例有问题,拿着报错信息去找方法也没遇到能解决问题的,最后怀疑是数据库配置和配置文件不匹配, 发现自己的数据库里并没有SQLEXPRESS ...
- [工作bug]c:import参数传递问题解析
一.起因: 在项目的工厂中,由于某个界面根据产品种类显示的产品属性均不相同,所以决定将界面进行拆分,将每一个产品写入一个jsp界面,分别命名为product0.jsp.product1.jsp,在主界 ...
- Java解析HTML之HTMLParser使用与详解
http://blog.csdn.net/jediael_lu/article/details/26285951
- 餐厅点餐系统app第二天
队友: 郭志豪:http://www.cnblogs.com/gzh13692021053/ 杨子健:http://www.cnblogs.com/yzj666/ 刘森松:http://www.cnb ...
- 纯CSS 实现tooltip 内容提示信息效果
Tooltip 也就是内容的提示信息,合理使用可以给用户比较好的体验. 实现方法有很多种,有很多JS 插件,我这里介绍的是纯CSS实现的方法,兼容性也比较靠谱,IE8+均可正常显示.实现方法也非常简单 ...
- Codeforces Round #253 (Div. 2) A. Anton and Letters
题目很简单,只需要注意带空格的输入用getline即可 #include <iostream> #include <vector> #include <algorithm ...
- POJ 1329 Circle Through Three Points(三角形外心)
题目链接 抄的外心模版.然后,输出认真一点.1Y. #include <cstdio> #include <cstring> #include <string> # ...
- How to create a project with Oracle Policy Modeling
This blog is about how to create a project with Oracle Policy Modeling. You can do it successfully i ...