简体   繁体   English

将 FlyOutItem 的 IsVisible 属性设置为 False 会导致 iOS 14.5 中的应用程序崩溃

[英]Setting IsVisible property of FlyOutItem to False results in app crash in iOS 14.5

The following is a snippet of FlyoutItem where the item needs to be shown if the user is logged in. Login process sets ShowAuthorizedRoutes to true if the login process is successful.以下是 FlyoutItem 的片段,如果用户登录,则需要在其中显示项目。如果登录过程成功,登录过程将ShowAuthorizedRoutes设置为 true。

  <FlyoutItem Title="Benefits Summary" IsVisible="{Binding ShowAuthorizedRoutes}">
        <ShellContent Route="BenefitsSummary" ContentTemplate="{DataTemplate local:BenefitsSummaryPage}" />
        <FlyoutItem.FlyoutIcon>
            <FontImageSource FontFamily="FontAwesome5154Solid" 
                                         Glyph="{x:Static fontAwesome:FontAwesomeIcons.DollarSign}" 
                                         Color="{x:StaticResource Secondary}"
                                         Size="Medium">
            </FontImageSource>
        </FlyoutItem.FlyoutIcon>
    </FlyoutItem>

The above snippet shows one of the FlyouItems in the Shell.上面的代码片段显示了 Shell 中的 FlyouItem 之一。 There are total 7 items in the Shell. Shell 共有 7 项。 They are identical except for the icon, route, and template.除了图标、路线和模板外,它们是相同的。 The last 2 items are not secured.最后 2 项未固定。 Therefore, they are not bound to ShowAuthorizedRoutes .因此,它们不受ShowAuthorizedRoutes的约束。 So, the visibility of 5 items needs to be toggled.因此,需要切换 5 个项目的可见性。

When login is successful, everything works as per the expectations.登录成功后,一切都按预期进行。 All items are shown.显示所有项目。 However, as soon as ShowAuthorizedRoutes is set to FALSE upon Logout, the app crashes in iOS 14.5 when it tries to hide the secured items.但是,一旦在注销时将ShowAuthorizedRoutes设置为 FALSE,该应用程序就会在 iOS 14.5 中尝试隐藏受保护的项目时崩溃。

The app center registers the following crash report.应用中心注册以下崩溃报告。

"attempt to delete row 5 from section 0, which only contains 2 rows before the update" “尝试从第 0 部分删除第 5 行,更新前仅包含 2 行”

It looks like that the Shell object is trying to delete items already deleted.看起来 Shell object 正在尝试删除已删除的项目。

If it is iOS 15 or later, this works without issues.如果它是 iOS 15 或更高版本,则可以正常工作。 It also works in Android (any version).它也适用于 Android(任何版本)。

Is there any suggestion to fix this on iOS 14 or any workaround?是否有任何建议可以在 iOS 14 或任何解决方法上解决此问题? Thanks in adv.谢谢你的建议。 for any help!寻求帮助!

What would happen if trying to move the logic into code behind?如果试图将逻辑移到后面的代码中会发生什么?

Try the following code, place it into AppShell .试试下面的代码,把它放到AppShell中。

if (ShowAuthorizedRoutes)
{
    foreach(ShellItem item in this.Items)
    {
       item.IsVisible = true;
    }
}
else
{
    foreach (ShellItem item in this.Items)
    {
       if (item.Title == "A" || item.Title == "B" ....)
       {
           item.IsVisible = false;
       }      
    }
}

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

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