How to Wait in Objective-C and Swift

2019-03-08 17:55发布

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) and finally changing the text to "Another text".

But sleep(2) only freezes the app and "Another text" is set without displaying "A text" for 2 seconds.

How may I display "A text" for 2 seconds and then show "Another text"?

7条回答
我欲成王,谁敢阻挡
2楼-- · 2019-03-08 18:44

You can use

[self performSelector:@selector(changeText:) withObject:text afterDelay:2.0];

or if you want to display it periodically, check the NSTimer class.

查看更多
登录 后发表回答