- (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 四种延时的方法的更多相关文章

  1. iOS中常用的四种数据持久化方法简介

    iOS中常用的四种数据持久化方法简介 iOS中的数据持久化方式,基本上有以下四种:属性列表.对象归档.SQLite3和Core Data 1.属性列表涉及到的主要类:NSUserDefaults,一般 ...

  2. WordPress忘记密码找回登录密码的四种行之有效的方法

    WordPress忘记密码找回登录密码的四种行之有效的方法 PS:20170214更新,感谢SuperDoge同学提供的方法,登入phpMyAdmin后,先从左边选自己的数据库,然后点上面的 SQL ...

  3. Scrapy里Selectors 四种基础的方法

    在Scrapy里面,Selectors 有四种基础的方法xpath():返回一系列的selectors,每一个select表示一个xpath参数表达式选择的节点css():返回一系列的selector ...

  4. java的四种取整方法

    java 中取整操作提供了四种方法:分别是: public static double ceil(double a)//向上取整  public static double floor(double ...

  5. Java_LIST使用方法和四种遍历arrayList方法

    1.List接口提供的适合于自身的常用方法均与索引有关,这是因为List集合为列表类型,以线性方式存储对象,可以通过对象的索引操作对象.   List接口的常用实现类有ArrayList和Linked ...

  6. Android Activity的四种经典传值方法

    文/ http://blog.csdn.net/sk719887916/article/details/41723613  skay 开发中遇到多个activity的传值问题 相邻两个之间的传值 或者 ...

  7. 笔试算法题(53):四种基本排序方法的性能特征(Selection,Insertion,Bubble,Shell)

    四种基本算法概述: 基本排序:选择,插入,冒泡,希尔.上述算法适用于小规模文件和特殊文件的排序,并不适合大规模随机排序的文件.前三种算法的执行时间与N2成正比,希尔算法的执行时间与N3/2(或更快)成 ...

  8. LayoutInflater中四种类型inflate方法的介绍

    转自:http://blog.csdn.net/aa4790139/archive/2011/05/07/6401556.aspx 第一种: public View inflate (int reso ...

  9. iOS四种多线程(swift和oc)

    在这篇文章中,我将为你整理一下 iOS 开发中几种多线程方案,以及其使用方法和注意事项.当然也会给出几种多线程的案例,在实际使用中感受它们的区别.还有一点需要说明的是,这篇文章将会使用 Swift 和 ...

随机推荐

  1. javac命令详解(下)

    摘自http://blog.csdn.net/hudashi/article/details/7058999 javac命令详解(下)                             -ver ...

  2. Unity 关于属性的get/set

    学习Unity的可能多数是C#转过来的, 一进来的时候你会发现Unity编写代码,在一些视频或文章中.基本都没有用过get/set使用, 多数是public string name;这样写的公开字段, ...

  3. Codeforces 474D Flowers dp(水

    题目链接:点击打开链接 思路: 给定T k表示T组測试数据 每组case [l,r] 有2种物品a b.b物品必须k个连续出现 问摆成一排后物品长度在[l,r]之间的方法数 思路: dp[i] = d ...

  4. ubuntu WiFi: operation not possible due to RF-kill《转载》

    Some people have been experiencing WiFi problems with Ubuntu 10.10 since an update that happend just ...

  5. [WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored (webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')

    WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored (webxml attribu ...

  6. PHP调用WCF小结

    新工作第三周,做了3年多的.Net,突然急转弯做PHP,漂移过弯,速度180迈 由于数据的整合,在项目中不得不使用PHP调用WCF 一头的雾水,网上相关的资料少又少,在phpChina发个帖子,还没有 ...

  7. JavaScript sort()方法比较器

    当我们想把一个由数字组成的数组进行简单的排序时,可能会想到sort()方法: var arr = [2 , 3, -1, -107, -14, 1]; console.log(arr.sort()) ...

  8. Eclipse开发Android项目安装配置

    在windows安装Android的开发环境不简单也说不上算复杂,本文写给第一次想在自己Windows上建立Android开发环境投入Android浪潮的朋友们,为了确保大家能顺利完成开发环境的搭建, ...

  9. Android studio教程:[6]创建多个Activity

    通常来说,一个android应用程序不止一个Activity(活动),更不止一个界面.于是需要创建多个Activity来满足应用程序的要求,这里我将告诉大家如何添加新的Activity,并实现Acti ...

  10. 单链表(Single Linked List)

    链表的结点结构  ┌───┬───┐  │data|next│  └───┴───┘ data域--存放结点值的数据域 next域--存放结点的直接后继的地址(位置)的指针域(链域) 实例:从终端输入 ...