zoukankan      html  css  js  c++  java
  • 线程睡眠

    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;

     

    }

     

    还是第二种方便。

  • 相关阅读:
    1924班网址
    20192414《网络空间安全导论》第一周学习总结
    H-Angry
    A-Plague Inc
    B-Rolling The Polygon
    F-Moving On
    A-Maximum Element In A Stack
    J-Word Search
    E-Pawns
    D-Lift Problems
  • 原文地址:https://www.cnblogs.com/guanliyang/p/3821760.html
Copyright © 2011-2022 走看看