Cocoa Touch - 加载 UITabBar 视图时显示活动指示器
我有一个 UITabBar 应用程序,有两个视图,它们在“viewWillAppear”方法中从网络加载大量数据。我想在检索此数据时显示进度条或活动指示器,以确保用户知道应用程序没有冻结。
我知道以前已经有人问过这个问题。我只需要澄清一下似乎是一个相当好的解决方案。
我已经实现了示例中的代码。该问题的最初提问者后来通过将数据检索放入另一个“线程”中解决了他们的问题。我理解线程的概念,但我不知道如何实现这一点。
通过研究,我发现我需要将所有繁重的数据检索移至后台线程,因为所有 UI 更新都发生在主线程中。
如果有人愿意为我提供一个例子,我将非常感激。我可以根据需要提供部分现有代码。
I have a UITabBar Application with two views that load large amounts of data from the web in their "viewWillAppear" methods. I want to show a progress bar or an activity indicator while this data is being retrieved, to make sure the user knows the app isn't frozen.
I am aware that this has been asked before. I simply need some clarification on what seems to be a rather good solution.
I have implimented the code in the example. The question's original asker later solved their problem, by putting the retrieval of data into another "thread". I understand the concept of threads, but I do not know how I would impliment this.
With research, I have found that I need to move all of my heavy data retrieval into a background thread, as all of the UI updating occurs in the main thread.
If one would be so kind as to provide an example for me, I would be very appreciative. I can provide parts of my existing code as necessary.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 NSURLConnection 它会自动在另一个线程上运行。
在你的 viewDidLoad: 中
,那么你需要一些自定义方法。如果您输入
-connection
并按 Esc 键,您将看到可以使用的所有不同方法。为此,您需要三个:这基本上就是全部了。 NSURLConnection 本身处理所有多线程,您不必担心。现在您可以创建一个活动指示器并显示它,它会起作用,因为主线程是空的。 :)
If you use NSURLConnection it runs on another thread automatically.
in your viewDidLoad:
then you need some custom methods. If you type in
-connection
and press Esc you'll see all the different methods you can use. There are three you will need with this:That is basically all there is to it. NSURLConnection handles all the multithreading itself and you don't have to worry. Now you can create an activity indicator and display it and it will work because the main thread is empty. :)