iOS 四种延时的方法[通俗易懂]

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];
        ;
    });
    //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];
    ;
}
– (void)delayMethod2{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@”” message:@”NSTimer延时” delegate:self cancelButtonTitle:@”确定” otherButtonTitles:@”取消”, nil];
    ;
}
– (void)delayMethod3{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@”” message:@”NSThread延时” delegate:self cancelButtonTitle:@”确定” otherButtonTitles:@”取消”, nil];
    ;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/115864.html原文链接:https://javaforall.net

(0)
上一篇 2022年1月29日 下午3:00
下一篇 2022年1月29日 下午3:00


相关推荐

  • Adaptive Thresholding

    Adaptive Thresholdinghttp://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htmAdaptiveThresholdingCommonNames: Adaptivethresholding,DynamicthresholdingBriefDescriptionThresholdingisusedtosegmenta

    2022年6月13日
    41
  • pycharm安装三方库_pycharm无网络安装第三方库

    pycharm安装三方库_pycharm无网络安装第三方库系统:mac10.15.3软件:2019.3pycharm导入第三方库的方法是1先点击File>OtherSetting>PreferencesforNewProjects2点击红框中的小+3在红线位置搜索要加载的第三方库,然后点击箭头所指的installPackage安装模块,点击后按钮按钮为灰色,等恢复后NumPy模块就已经安装完成了,并且显示在列表中,…

    2022年8月27日
    4
  • 安卓chrome 扫描二维码_付款扫的是条形码还是二维码

    安卓chrome 扫描二维码_付款扫的是条形码还是二维码了解二维码这个东西还是从微信中,当时微信推出二维码扫描功能,自己感觉挺新颖的,从一张图片中扫一下竟然能直接加好友,不可思议啊,那时候还不了解二维码,呵呵,然后做项目的时候,老板说要加上二维码扫描功能,然后自己的屁颠屁颠的去百度,google啥的,发现很多朋友都有介绍二维码扫描的功能,然后我就跟着人家的介绍自己搞起了二维码扫描功能,跟着人家的帖子,很快我的项目就加入了扫描二维码的功能,然后自己还很开

    2025年8月20日
    3
  • Robotium 常用方法

    Robotium 常用方法①点击:clickOnButton(int)//ClicksonaButtonwithagivenindex.clickOnButton(String)//ClicksonaButtonwithagiventext.clickOnCheckBox(int)//ClicksonaCheckBoxwithagivenindex.clickOnVie

    2022年7月25日
    17
  • 星火大模型web入口及使用教程

    星火大模型web入口及使用教程

    2026年3月14日
    3
  • Jmeter之性能测试TPS解析

    Jmeter之性能测试TPS解析1 获得 TPS 插件 https www cnblogs com beginner boy p 7806220 html 参见 已保存百度云盘 2 添加后 记得使用调度器 每秒 50 个并发 持续 60 秒 观察 TPS3 TPS 执行一次事务 包括请求 请求服务器 等待服务器返回等等 比如一个 TPS 事务 可能触发 3 个 QPS 请求 PS 一秒钟处理的事务数 TPS 值越大 一秒钟处理的事

    2026年3月26日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号