Xamarin.Forms.Application.Current.MainPage为空

Xamarin.Forms.Application.Current.MainPage为空,xamarin.forms,xamarin.ios,prism,application-lifecycle,Xamarin.forms,Xamarin.ios,Prism,Application Lifecycle,我有一个不寻常的场景,我正在将应用程序从iOS迁移到表单 我的设置是- iOS项目加载签名UIViewController和handelling登录例程。 主页为空 登录例程完成后,我将XF视图作为UIViewController加载,并将其添加到导航堆栈中 var formscocontroller=formsPage.CreateViewController(); CoreApplication.Instance.FormsController=FormsController; var

我有一个不寻常的场景,我正在将应用程序从iOS迁移到表单

我的设置是-

  • iOS项目加载签名UIViewController和handelling登录例程。 主页为空

  • 登录例程完成后,我将XF视图作为UIViewController加载,并将其添加到导航堆栈中

  • var formscocontroller=formsPage.CreateViewController();
    CoreApplication.Instance.FormsController=FormsController;
    var CurrentNavigationController=UIApplication.SharedApplication.KeyWindow.RootViewController;
    var VIEWCONTROLLERSTACK=CurrentNavigationController.ChildViewController;
    viewControllersStack[viewControllersStack.Length-1].NavigationController.PushViewController(CoreApplication.Instance.FormsController,true);
    
    这就是主页具有导航值的时候,将其设置为导航页面

  • 我转到背景
  • protectedoverride void OnSleep()
    {
    if(Application.Current.MainPage!=null)
    {
    Console.WriteLine(“!!!!-->”+Application.Current.MainPage.GetType().Name);
    }
    }
    
    我正在获取主页的名称-所以该值不为空

  • 我回到前台=>OnResume()捕捉到主页为空
  • 但我要回到我的XF视图。 导航在页面之间工作,一切似乎都很好

    现在唯一的问题是,因为MainPage现在是空的-一些库,比如Rg.Plugins.Popup,由于它们引用了MainPage,所以无法工作,我遇到了崩溃

    有没有关于如何保持主页引用的帮助/想法

    谢谢大家!

    PS

    如果我调用NavigationService.NavigateAsync(MyPage),我会做一些调查;来自App.xaml.cs
    或者do=>MainPage=newmypage();然后,主页实例在所有应用程序生命周期中都保持活动状态。

    从评论到原始帖子,问题的解决方法是在XF成为应用程序启动时的第一响应者时移动应用程序逻辑。然后,当需要加载UIViecontrollers时,我将正常管理导航-获取UIApplication.SharedApplication.KeyWindow以显示ViewController


    有关如何执行此操作的更多详细信息,请参见

    ,这意味着您的问题现在已解决?是和否。问题保持不变。目前,我正在研究的解决方案(仍在摸索导航)来自我的Post Scriptum=>我必须将应用程序从Xamarin.iOS first/Xamarin.Forms second转换为Xamarin.iOS second/Xamarin.Forms first。我一做完就在这里发布结果。