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 和 ...
随机推荐
- 探索PHP+Nginx(二) 安装PHP
首先,我们简单了解一下什么是PHP,PHP(Hypertext Preprocessor 超文本预处理器) 和Java语言一样,PHP也是属于高级语言,并不能直接在操作系统上运行.Java运行需要虚拟 ...
- XMPP通讯开发-仿QQ显示好友列表和用户组
在 XMPP通讯开发-服务器好友获取以及监听状态变化 中我们获取服务器上的用户好友信息,然后结合XMPP通讯开发-好友获取界面设计 我们将两个合并起来,首先获取用户组,然后把用户组用List ...
- python 性能优化
1.优化循环 循环之外能做的事不要放在循环内,比如下面的优化可以快一倍 2.使用join合并迭代器中的字符串 join对于累加的方式,有大约5倍的提升 3.使用if is 使用if is True比i ...
- linux查看用户登录信息2-who命令
who命令与w命令相似,但要比w命令显示更加详细的信息.[root@rusky opt]# man who WHO(1) User Commands WHO(1) NAME who - show wh ...
- 使用FindControl("id")查找控件 返回值都是Null的问题
做了一个通过字符串ID查找页面控件并且给页面控件赋值的功能,过程中遇到了this.FindControl("id")返回值都是Null的问题,记录一下解决办法. 问题的原因是我所要 ...
- MVC 笔记(二)
HttpUtility.HtmlEncode来预处理用户输入,这能阻止用户向视图中用链接注入js代码或html标记 .[Required]:非空验证 .[StringLength(**)]:设置字符的 ...
- Arrays.copyof
public static int[] copyOf(int[] original, int newLength) { int[] copy = new int[newLength]; System. ...
- 微信SDK导入报错 Undefined symbols for architecture i386:"operator delete[](void*)", referenced from:
异常信息: Undefined symbols for architecture i386: "operator delete[](void*)", referenced fro ...
- 基于excel9.h的excel处理
基于excel9.h的excel处理; #include "excel9.h" #include <iostream> using namespace std; cla ...
- jquery 实现简单拖拽
$.fn.drag = function(obj) { var dragging = false; var oDrag = $(obj); oDrag.mousedown(function(e) { ...