为 Monotouch 应用程序创建加载屏幕类的最佳方法是什么?

发布于 2024-12-09 04:25:26 字数 254 浏览 0 评论 0原文

在我的应用程序启动之前,我需要加载和处理很多事情,所以当我在 iPhone 上测试它时,它总是被 iOS 杀死,因为它挂起 iPhone 的时间太长了。

然后我决定为我的应用程序编写一个加载屏幕类,它可以立即显示徽标和进度指示器(保持响应以避免被 iOS 杀死),同时在后台有一个单独的线程初始化我的所有 ViewController,然后关闭加载屏幕并显示主窗口。

使用 MonoTouch 实现此目的的最佳方法是什么?

欢迎任何建议。 谢谢。

I need to load and process many things before my app starts, so when I test it on my iPhone it's always killed by iOS because it hangs the iPhone for too much time.

I then decided to write a loading screen class for my Apps, something that shows immediatly a logo and a progress indicator (keeping it responsive to avoid being killed by iOS), while in a background a separate thread initializes all my ViewControllers and then closes the loading screen and shows the main window.

What is the best way to do it with MonoTouch?

Any suggestion is welcome.
Thank you.

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

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

发布评论

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

评论(1

晌融 2024-12-16 04:25:26

我是这样做的:

在 FinishedLaunching 方法中,初始化初始视图并将其添加到主窗口:

window.AddSubview(this.splashView);

之后,调用您的代码来执行您想要在线程/异步调用中执行的所有操作。我通常使用线程池。记住在主线程上调用:

ThreadPool.QueueUserWorkItem(delegate {
    this.BeginInvokeOnMainThread(delegate {
        //Initialize stuff here
        //...
        //when done, add your initial view to the window and remove the splash view
        //eg.:
        //window.AddSubview(myController.View);
        //this.splashView.RemoveFromSuperview();
    });
});

// show the window, which only displays the splash view now and return
window.MakeKeyAndVisible();
return true;

一个粗略的例子,但我希望它有帮助。

This is how I do it:

In the FinishedLaunching method, initialize and add your splash view to the main window:

window.AddSubview(this.splashView);

After that, invoke your code that does all the stuff you want to do in a thread/async invocation. I usually use the ThreadPool. Remember to invoke on the main thread:

ThreadPool.QueueUserWorkItem(delegate {
    this.BeginInvokeOnMainThread(delegate {
        //Initialize stuff here
        //...
        //when done, add your initial view to the window and remove the splash view
        //eg.:
        //window.AddSubview(myController.View);
        //this.splashView.RemoveFromSuperview();
    });
});

// show the window, which only displays the splash view now and return
window.MakeKeyAndVisible();
return true;

A rough example, but I hope it helps.

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