How to Wait in Objective-C and Swift

后端 未结 8 806
自闭症患者
自闭症患者 2021-01-31 02:22

I want to change my UILabel\'s text after 2 seconds.

I tried setting my UILabel\'s text to \"A text\", and use sleep(2) a

8条回答
  •  一生所求
    2021-01-31 02:50

    You can accomplish this with a timer, e.g.

       NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(eventToFire:) userInfo:nil repeats:YES]; // Fire every 4 seconds.
    
       ...
    
       - (void)eventToFire:(NSTimer*)timer {
          // Do Something
       }
    

提交回复
热议问题