导航控制器中的 UIActivityIndicatorView 和 UITableView
我正在开发一个非常简单的应用程序 带有表格视图的导航控制器 当用户单击一行时,他将被定向到详细信息视图。
但是,详细信息视图从核心数据中提取数据。我正在提取相对大量的数据,加载大约需要三秒钟。
我想添加 UIActivityIndicatorView 来显示进度。
我尝试在用户单击该行后启动动画,因此我将其设置为在 didSelectRowAtIndexPath 中进行动画处理。
出于某种原因,活动指示器在推送详细信息视图之前不会启动。
知道为什么吗?或者实现这个想法的最佳方法?
~阿达姆
I am working on a an application which is very simple
a navigation controller with a table view
when the user clicks a row, he is directed to the details view.
However, the details view pulls data from Core Data. i am pulling a relatively large amount of data that takes about three seconds to load.
I wanted to add that UIActivityIndicatorView to show progress.
I tried to start the animation once the user clicks the row, so i set it to animate in didSelectRowAtIndexPath
For some reason, the Activity Indicator doesn't start before the pushing of the details view.
Any idea why? or the best way to implement such an idea?
~Adham
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为您启动动画,然后在同一线程中启动大型操作。考虑在新线程中运行 3 秒的操作。查看 NSOperationQueue,然后创建一个 NSOperation 来运行该过程。它将以这种方式工作。
Because you start the animation and then start a large operation in the same thread. Consider running that 3 second operation in a new thread. Look at
NSOperationQueue
and then create aNSOperation
to run that procedure. It will work this way.在运行循环结束之前,UI 不会更新。您将按顺序显示活动监视器,然后推送新的表视图,然后 UI 更新。您需要更改此顺序。
您可以将某些内容移动到不同的线程,也可以通过调用
performSelector:afterDelay:
并延迟 0 来延迟新表视图的加载。这将延迟新表的加载直到活动指示器出现在 UI 中后才可查看。现在,它仍然都在同一个线程上,因此您将被阻止执行任何操作,但如果动画在活动监视器中线程化,它将成为一个快速且简单的解决方案。The UI doesn't update until the end of your run loop. You are, in sequence, displaying the activity monitor, then pushing the new table view, and then the UI updates. You need to change this order.
You can either move something to a different thread, or you could perhaps delay the loading of the new table view by calling
performSelector:afterDelay:
with a delay of 0. That will delay the loading of the new table view until after the activity indicator appears in the UI. Now, it's still all on the same thread, so you will be blocked from doing anything, but if the animation is threaded in the activity monitor, it would make for a quick and easy solution.线程中调用方法:
详细信息请参见以下内容:
http://iphone.zcentric.com/?s=UIActivityIndicatorView
Call method in thread:
See following for more details:
http://iphone.zcentric.com/?s=UIActivityIndicatorView