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 和 ...
随机推荐
- 解决cognos以远程db2数据库为数据源的连接失败问题
问题现象为使用远程的db2来创建数据源时,测试连接时不通,好多人都说是驱动问题,将db2cc.jar拷贝到某lib目录下,实验不通: 在看到某哥们的博客时最后提了一句,说需要将数据库catalog到本 ...
- ModelAndView解析
查看spring的帮助文档得到下面信息: org.springframework.web.servlet Class ModelAndViewjava.lang.Object org.springfr ...
- Android应用程序组件Content Provider在应用程序之间共享数据的原理分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6967204 在Android系统中,不同的应用 ...
- qt获取本机网络信息
networkinformation.h #include<QtGui/QWidget> #include<QLabel> #include<QPushButton> ...
- 【高精度+DP】【HDU1223】 OrderCount
Order Count Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- android中页面的返回刷新
android中从A activity 打开B activity 操作之后返回A activity,并且A activity状态改变就要用到刷新 我就介绍一下我开发中最常用的方法 引用函数 setRe ...
- c++中各种数据类型所占字节
求各种数据类型所占用的字节数可调用sizeof函数,求各种数据类型的最大值可以调用limits标准库中的numeric_limits<T>::max(),numeric_limits< ...
- Oracle 中的Userenv()
1.USEREVN() 返回当前用户环境的信息,opt可以是:ENTRYID,SESSIONID,TERMINAL,ISDBA,LABLE,LANGUAGE,CLIENT_INFO,LANG,VSIZ ...
- servlet 之 返回json数据并显示
//实体类import java.util.ArrayList; public class ObjectType { private String type; private ArrayList< ...
- poj 01背包
首先我是按这篇文章来确定题目的. poj3624 Charm Bracelet 模板题 没有要求填满,所以初始化为0就行 #include<cstdio> #include<algo ...