【问题标题】:What is the best way to create a loading screen class for a Monotouch App?为 Monotouch 应用程序创建加载屏幕类的最佳方法是什么?
【发布时间】:2011-10-07 10:28:16
【问题描述】:

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

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

使用 MonoTouch 的最佳方法是什么?

欢迎提出任何建议。 谢谢。

【问题讨论】:

    标签: ios multithreading asynchronous xamarin.ios loading


    【解决方案1】:

    这就是我的做法:

    在 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;
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-01
      • 1970-01-01
      • 2021-03-18
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 2021-07-25
      • 2011-02-10
      相关资源
      最近更新 更多