简体   繁体   中英

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 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. There are total 7 items in the Shell. They are identical except for the icon, route, and template. The last 2 items are not secured. Therefore, they are not bound to ShowAuthorizedRoutes . So, the visibility of 5 items needs to be toggled.

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.

The app center registers the following crash report.

"attempt to delete row 5 from section 0, which only contains 2 rows before the update"

It looks like that the Shell object is trying to delete items already deleted.

If it is iOS 15 or later, this works without issues. It also works in Android (any version).

Is there any suggestion to fix this on iOS 14 or any workaround? 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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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