当我的应用程序加载其资源时,UIProgressView 未更新

发布于 2024-08-02 01:39:24 字数 444 浏览 10 评论 0原文

我正在尝试在长时间的资源加载过程中更新 UIView 中的 UIProgressView 进度条。 假设我正在从 NIB 文件加载一堆位图(大概有一百个)。 加载 10 后,我向 UIProgressView 发出 .progress,该 UIProgressView 是已显示的 UIView 的一部分。 因此,我发出:

myView.myProgressView.progress=0.2;

然后,我加载另外 10 个位图,然后发出:

myView.myProgressView.progress=0.4;

等等。 当应用程序运行时,进度条不会前进。 它只是停留在其初始位置。 冒着听起来像个白痴的风险,我是否必须在单独的线程上加载资源,以便操作系统可以更新 UI,或者是否有更简单的方法? 感谢您的任何帮助。

I am trying to update a UIProgressView progress bar that I have in a UIView during a long resource loading process. Let's say I'm loading a bunch of bitmaps from a NIB file (like maybe a hundred). After I load 10, I issue a .progress to the UIProgressView that is part of a UIView that is already being displayed. So, I issue:

myView.myProgressView.progress=0.2;

Then, I load another 10 bitmaps, and issue:

myView.myProgressView.progress=0.4;

etc., etc. When the app runs, the progress bar doesn't advance. It simply stays at its initial position. At the risk of sounding like a complete moron, do I have to load my resources on a separate thread so the OS can update the UI, or, is there an easier way? Thanks for any assistance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

暖树树初阳… 2024-08-09 01:39:24

是的。 将它们加载到单独的线程上。 或者只是使用类似 performSelector 的东西:(

[self performSelector:@selector(setProgressBar) withObject:nil afterDelay:0.0];

并创建一个 setProgressBar 函数,该函数从成员变量中读取当前值并更新 UI)

Yes. Load them on a separate thread. Or just use something like performSelector:

[self performSelector:@selector(setProgressBar) withObject:nil afterDelay:0.0];

(and create a setProgressBar function which reads the current value from a member variable and updates the UI)

感受沵的脚步 2024-08-09 01:39:24

您可以在每次更新 UI 后运行运行循环的一个步骤:

SInt32 result;
do {
    result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);
} while(result == kCFRunLoopRunHandledSource);

它可能会产生其他不良后果(例如,使用户能够与 UI 交互、在用户执行之前执行视图控制器的委托,例如 viewDidAppear)应该被执行,等等)所以要非常非常小心。

You could run a step of the runloop after each update of the UI:

SInt32 result;
do {
    result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0, TRUE);
} while(result == kCFRunLoopRunHandledSource);

It could have other bad consequences (for example, enable user to interact with the UI, execute delegates of view controller such as viewDidAppear before they should be executed, etc) so be very, very careful.

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