如何在后台线程中准备UI? [英] How do I prepare my UI in a background thread?

查看:96
本文介绍了如何在后台线程中准备UI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A UIViewController大约需要半秒钟来加载其内容并显示在屏幕上.如何使它们全部在后台加载并在它们准备好后出现?

A UIViewController takes about half a second to load its contents and appear on screen. How can I make them all load in the background and appear when they're ready?

推荐答案

有一个 Apple开发者网站上的rel ="nofollow"> LazyTableImages 示例.

它显示了如何在后台线程中执行繁重任务并更新主线程上的UI.

It shows how to perform the heavy lifting in a background thread and update the UI on the main thread.

PerformSelectorInBackground:withObject:是一种可能的解决方案,尽管更现代的方法是使用异步块.您可以在这些块中的主线程上运行代码,以安全地更新UI.

PerformSelectorInBackground:withObject: is a possible solution, although a more modern method would be to use asynchronous blocks. You can run code on the main thread from within these blocks to update the UI Safely.

《并发编程指南》 是查找更多信息和示例的好地方.

The Concurrency Programming Guide is a good place to find more information and examples of this.

这篇关于如何在后台线程中准备UI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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