更新标签需要太长时间(快速) [英] Updating label takes too long (swift)

查看:79
本文介绍了更新标签需要太长时间(快速)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是初学者的快速开发者。我很喜欢这个天气应用程序。我正在下载网站数据,然后在我的标签上显示。

I'm beginner swift developer. I'm stucked with this weather app.I'm downloading website data and then displaying in my label.

不幸的是,整个过程需要10秒才能更新我的标签。

Unfortunately this whole process takes like 10 second to update my label.

这可能不是因为网络连接,因为控制台会立即更新。

This is probably not because of the network connection as the console is updated instantly.

感谢您的建议。

推荐答案

该代码可能在辅助线程上运行。您所做的任何UI更改都应在主线程上进行。所以试试这个:

What happens is that code is probably run on a secondary thread. Any UI changes you make should be made on the main thread. So try this:

dispatch_async(dispatch_get_main_queue()) {
    // update label
}

这应立即更新您的标签。

This should update your label instantly.

这篇关于更新标签需要太长时间(快速)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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