如何在Objective-C和Swift中等待 [英] How to Wait in Objective-C and Swift

查看:188
本文介绍了如何在Objective-C和Swift中等待的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在2秒后更改我的 UILabel 的文字。

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

我尝试设置我的 UILabel 的文字为A text,并使用 sleep(2)并最终更改文本到另一个文本

I tried setting my UILabel's text to "A text", and use sleep(2) and finally changing the text to "Another text".

但是 sleep(2)只能冻结该应用程序和另一个文本的设置没有显示A text 2秒。

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

怎么可能我显示A text 2秒,然后显示Another text

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

推荐答案

你可以使用

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

或者如果你想定期显示它,请检查 NSTimer class。

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

这篇关于如何在Objective-C和Swift中等待的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆