导航控制器中的 UIActivityIndi​​catorView 和 UITableView

发布于 2024-08-11 11:40:33 字数 305 浏览 5 评论 0原文

我正在开发一个非常简单的应用程序 带有表格视图的导航控制器 当用户单击一行时,他将被定向到详细信息视图。

但是,详细信息视图从核心数据中提取数据。我正在提取相对大量的数据,加载大约需要三秒钟。

我想添加 UIActivityIndi​​catorView 来显示进度。

我尝试在用户单击该行后启动动画,因此我将其设置为在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

荒岛晴空 2024-08-18 11:40:33

因为您启动动画,然后在同一线程中启动大型操作。考虑在新线程中运行 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 a NSOperation to run that procedure. It will work this way.

时光礼记 2024-08-18 11:40:33

在运行循环结束之前,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.

罪歌 2024-08-18 11:40:33

线程中调用方法:

[NSThread detachNewThreadSelector: @selector(loadMethod) toTarget:self withObject:nil];

详细信息请参见以下内容:
http://iphone.zcentric.com/?s=UIActivityIndi​​catorView

Call method in thread:

[NSThread detachNewThreadSelector: @selector(loadMethod) toTarget:self withObject:nil];

See following for more details:
http://iphone.zcentric.com/?s=UIActivityIndicatorView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文