iOS 四种延时的方法
- (void)initBlock{
//延时的方法
//1:GCD延时 此方式在能够在參数中选择运行的线程。
是一种非堵塞的运行方式,没有找到取消运行的方法。
double delay1=2.0;//设置延时时间
dispatch_time_t popTime=dispatch_time(DISPATCH_TIME_NOW, delay1 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"GCD延时" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
[alert show];
});
//2:NSTimer延时,此方式要求必须在主线程中运行。否则无效。是一种非堵塞的运行方式,能够通过NSTimer类的- (void)invalidate;取消运行。
[NSTimer scheduledTimerWithTimeInterval:8.0f target:self selector:@selector(delayMethod2) userInfo:nil repeats:NO];
//3:PerformSelector延时
[self performSelector:@selector(delayMethod) withObject:nil afterDelay:5.0f];
//4:NSThread 延时
[NSThread sleepForTimeInterval:11.0f];
[self delayMethod3];
}
- (void)delayMethod{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"PerformSelector延时" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
[alert show];
}
- (void)delayMethod2{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"NSTimer延时" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
[alert show];
}
- (void)delayMethod3{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:@"NSThread延时" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
[alert show];
}
iOS 四种延时的方法的更多相关文章
- iOS中常用的四种数据持久化方法简介
iOS中常用的四种数据持久化方法简介 iOS中的数据持久化方式,基本上有以下四种:属性列表.对象归档.SQLite3和Core Data 1.属性列表涉及到的主要类:NSUserDefaults,一般 ...
- WordPress忘记密码找回登录密码的四种行之有效的方法
WordPress忘记密码找回登录密码的四种行之有效的方法 PS:20170214更新,感谢SuperDoge同学提供的方法,登入phpMyAdmin后,先从左边选自己的数据库,然后点上面的 SQL ...
- Scrapy里Selectors 四种基础的方法
在Scrapy里面,Selectors 有四种基础的方法xpath():返回一系列的selectors,每一个select表示一个xpath参数表达式选择的节点css():返回一系列的selector ...
- java的四种取整方法
java 中取整操作提供了四种方法:分别是: public static double ceil(double a)//向上取整 public static double floor(double ...
- Java_LIST使用方法和四种遍历arrayList方法
1.List接口提供的适合于自身的常用方法均与索引有关,这是因为List集合为列表类型,以线性方式存储对象,可以通过对象的索引操作对象. List接口的常用实现类有ArrayList和Linked ...
- Android Activity的四种经典传值方法
文/ http://blog.csdn.net/sk719887916/article/details/41723613 skay 开发中遇到多个activity的传值问题 相邻两个之间的传值 或者 ...
- 笔试算法题(53):四种基本排序方法的性能特征(Selection,Insertion,Bubble,Shell)
四种基本算法概述: 基本排序:选择,插入,冒泡,希尔.上述算法适用于小规模文件和特殊文件的排序,并不适合大规模随机排序的文件.前三种算法的执行时间与N2成正比,希尔算法的执行时间与N3/2(或更快)成 ...
- LayoutInflater中四种类型inflate方法的介绍
转自:http://blog.csdn.net/aa4790139/archive/2011/05/07/6401556.aspx 第一种: public View inflate (int reso ...
- iOS四种多线程(swift和oc)
在这篇文章中,我将为你整理一下 iOS 开发中几种多线程方案,以及其使用方法和注意事项.当然也会给出几种多线程的案例,在实际使用中感受它们的区别.还有一点需要说明的是,这篇文章将会使用 Swift 和 ...
随机推荐
- initial pointer [expert c]
initial differece between pointer and array Both arrays and pointers can be initialized with a liter ...
- 记事本写hello world_Java
1 新建记事本,重命名为hello.java 2 打开hello.java,编辑并保存 class Hello { public static void main(String[] args) { S ...
- 解决 VM虚拟机网卡无法拉起 的问题
复制虚拟机后,第二块网卡始终无法正常运作,表现为无法自动获得dhcp地址,且重启后与第一块网卡使用同样的地址,让人苦笑不得,反复重启了很多次都是这样,后面想到ifcfg-eth1的配置文件可能写得太简 ...
- JavaScript 运行机制详解:深入理解Event Loop
Philip Roberts的演讲<Help, I'm stuck in an event-loop>,详细.完整.正确地描述JavaScript引擎的内部运行机制. 一.为什么JavaS ...
- 代码中实际运用memcached——.NET
本文取自:http://blog.csdn.net/dyllove98/article/details/9115947 memcached安装:============================ ...
- SQL Server 日期函数:某天是星期几?
[鹏城万里] 发表于 www.sqlstudy.com 要得到某一天是星期几,需要用到 SQL Server 中的日期函数:datename(). 今天是星期几,例子 1: set language ...
- Java - 反射机制(Reflection)
Java - 反射机制(Reflection) > Reflection 是被视为 动态语言的关键,反射机制允许程序在执行期借助于 Reflection API 取得任何类的 ...
- ThinkPHP使用Memcached缓存数据
ThinkPHP默认使用文件缓存数据,支持Memcache等其他缓存方式,有两个PHP扩展:Memcache和Memcached,Memcahe官方有说明,主要说一下Memcached. 相对于PHP ...
- 在linq查询环境下通过sql语句来访问数据库
接上一篇随笔 这里主要介绍在linq环境下,如果实现用sql来访问数据库,同时也介绍在EF框架中如何添加新的方法来访问数据库. 1.首先,在数据访问层(EF.DAO,EF.IDAO)中添加具体的函数来 ...
- 【web开发--js学习】functionName 如果是一个属性值,函数将不会被调用
<html> <head> <meta http-equiv="Content-Type" Content="text/html; char ...