当核心数据存储迁移到新版本时,在 iPhone 应用程序的启动屏幕上显示 MBProgressHUD?

发布于 2024-11-03 21:13:35 字数 258 浏览 2 评论 0原文

如果我的 iPhone 应用程序需要更新核心数据数据库,我想显示 MBProgressHUD当我的 iPhone 应用程序加载时向用户查看,这样他们就知道它正在运行而不是挂起。在迁移数据存储时,如何将 MBProgressHUD 添加到启动屏幕?通常我会将其附加到 UIViewController 的视图,但启动屏幕位于应用程序委托下方。这可以吗?

If my iPhone app needs to update the Core Data database, I would like to show an MBProgressHUD view to users while my iPhone app is loading, so they know that it's working and not hanging. How might I go about adding an MBProgressHUD to the splash screen while the data store is migrating? Normally I would attach it to the UIViewController's view, but the splash screen is under the app delegate. Is this possible to do?

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

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

发布评论

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

评论(2

森林迷了鹿 2024-11-10 21:13:35

不,不可能在启动屏幕上覆盖任何内容,因为它是静态的。

但是,您可以将密集型过程延迟一段时间,直到应用程序加载,然后创建一个带有进度指示器的假启动屏幕,同时密集型工作在后台线程中进行。

No it is not possible to overlay anything over the splash screen as it's static.

You could, however, delay the intensive process for a bit until the app loads, then create a fake splash screen with the progress indicator while the intensive stuff goes on in a background thread.

寻找我们的幸福 2024-11-10 21:13:35

您可以在应用程序委托头文件(或“全局”头文件)中创建一个 #define 宏,如下所示:

#define MyAppDelegate [[UIApplication sharedApplication] delegate]

然后,当您想要访问应用程序委托属性时,您可以这样做您在应用程序中的任何位置导入了该标头(或全局标头):

MyAppDelegate.property = foo;
[[MyAppDelegate property] bar];

这可以帮助您在应用程序生命周期的任何时刻管理进度视图。

编辑

sudo rm -rf 是正确的,您无法在启动屏幕期间进行工作。但是您可以在应用程序委托的 -applicationDidFinishLaunching: 方法中启动进度视图,然后在后台线程上启动工作。后台线程的工作完成后,请使用回调关闭进度视图。

You could create a #define macro in your application delegate header file (or in a "globals" header), like so:

#define MyAppDelegate [[UIApplication sharedApplication] delegate]

Then, when you want access the application delegate property, you can do so like this anywhere in your application you have imported that header (or the globals header):

MyAppDelegate.property = foo;
[[MyAppDelegate property] bar];

This may help you manage your progress view at any point in the app's life.

EDIT

sudo rm -rf is correct that you can't do work during the splash screen. But you can start your progress view in the app delegate's -applicationDidFinishLaunching: method, and then launch work on a background thread. Once your background thread's work is finished, have a callback dismiss the progress view.

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