• 线程睡眠


    1,睡眠方法。[NSThread sleepForTimeInterval:3];

    关于程序睡眠这里收集了两种方法,看下面代码

    - (IBAction)setButton:(id)sender {

        _label.text = @"对方正在思考";

     

        [self performSelector:@selector(run1) withObject:nil afterDelay:2];

     

        [NSThread detachNewThreadSelector:@selector(run) toTarget:self withObject:nil];

        

    }

     

    -(void) run{

        [NSThread sleepForTimeInterval:3];

        _label.text = @"对方完成动作";

    }

     

    -(void) run1{

        _label.text = @"111";

    }

     

    第一种 [self performSelector:@selector(run1)withObject:nil afterDelay:3];是消息处理方法, 分别传入方法,传入方法参数和返回时间。

    第二种 则创建了一个新线程。

     

    所以能搞点有趣的代码了

    - (IBAction)setButton:(id)sender {

        _label.text = @"对方正在思考";

        

        [self performSelector:@selector(run1:) withObject:@"第一次" afterDelay:3];

        [self performSelector:@selector(run1:) withObject:@"两次就熟悉了吧" afterDelay:5];

        [self performSelector:@selector(run1:) withObject:@"看什么看" afterDelay:7];

        [self performSelector:@selector(run1:) withObject:@"再看打爆你的眼睛" afterDelay:10];

    }

     

    -(void) run1:(NSString *) str{

     

        _label.text = str;

     

    }

     

    还是第二种方便。

  • 相关阅读:
    在Js或者cess后加版本号 防止浏览器缓存
    svn操作
    Hash表
    网站js埋点
    c#优秀文章
    CentOS修改默认yum源为国内yum镜像源
    mysql开启远程连接
    安装jdk环境
    Eclipse的一下设置
    好用的在线HTML、CSS工具
  • 原文地址:https://www.cnblogs.com/guanliyang/p/3821760.html
Copyright © 2020-2023  润新知