繁体   English   中英

Xamarin Forms iOS 中的 ContentPage 的生命周期是什么?为什么当我切换到另一个应用程序时它会崩溃?

[英]What is the life cycle of a ContentPage in Xamarin Forms iOS and why does it crash when I switch to another app?

当我从 ContentPage 切换到另一个应用程序时,我的Xamarin iOS应用程序在ContentPage上崩溃。

第一次出现在 label 渲染器中,所以我将它包装在一个 try catch 块中:

protected override void OnElementChanged(ElementChangedEventArgs<Label> e)
{
    //Add a try because of this:    
    //https://stackoverflow.com/questions/46881393/ios-crash-report-unexpected-start-state-exception
    try
    {
        base.OnElementChanged(e);

        if (label != null)
        {
            sv = label.Parent as ScrollViewEx;
        }
    }
    catch
    {

    }

}

现在,当我关闭时,它在应用程序的另一部分崩溃,试图访问已处置的编辑器 object。

关于操作系统为何在这种情况下尝试重新渲染 UI 对象,我需要了解这里发生的生命周期事件吗?

我如何才能在一般情况下保护我的应用程序免受此类崩溃的影响,而不必仅仅因为我正在切换到另一个应用程序而将每个 UI object 包装在 try catch 中?

我不熟悉这个问题,但是,我可以推荐的是在 catch 关键字的末尾,将 (Exception e) 作为参数

try
{...}
catch(Exception e)
{
    Debug.WriteLine(e.Message);
}

这样你就离解决这个痛苦的错误更近了一步。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM