Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] [iOS] [Shell] NullReferenceException when remove tab programmatically #14142

Open
pablogupi opened this issue Apr 11, 2021 · 1 comment
Labels
a/shell 🐚 i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎 t/bug 🐛

Comments

@pablogupi
Copy link

Description

Only in ios when the only tab that exists is removed and a new one is added, a NullReferenceException type error appears.
On Android this code works perfectly
Xamarin.Forms.Platform.iOS

System.NullReferenceException
Object reference not set to an instance of an object

Steps to Reproduce

This is the typical code to show a tutorial the first time the app is used

  1. In AppShell.xml create a empty TabBar
    <TabBar x:Name="tabApp"/ >
  2. In AppShell.cs constructor add new tab:
                Shell.SetNavBarIsVisible(this, false);
                ShellSection shell_section = new ShellSection { Title = "Start", Icon = "tab_about.png" };
                shell_section.Items.Add(new ShellContent() { Content = new TutorialPageVIew() });
                tabApp.Items.Add(shell_section);
  1. After finish tutorial, remove tab and add another.
 public static  void StartApp(AppShell app)
       {
           if (app.tabApp.Items.Count > 0)
           {
               app.tabApp.Items.Clear();
           }
           Shell.SetNavBarIsVisible(app, true);


           ShellSection shell_section = new ShellSection { Title = "Start", Icon = "tab_about.png" };
           shell_section.Items.Add(new ShellContent() { Content = new StartPageView() });
           app.tabApp.Items.Add(shell_section);

The NullReferenceException error appears on this line: app.tabApp.Items.Add(shell_section); Only on iOS
If I delete this line app.tabApp.Items.Clear(); the result is two tabs (Tutorial and StartPage).
If I add this line app.tabApp.Items.RemoveAt(0); after add StartPage, the result is correct:

public static  void StartApp(AppShell app)
        {
            if (app.tabApp.Items.Count > 0)
            {
                //app.tabApp.Items.Clear();
            }
            Shell.SetNavBarIsVisible(app, true);


            ShellSection shell_section = new ShellSection { Title = "Start", Icon = "tab_about.png" };
            shell_section.Items.Add(new ShellContent() { Content = new StartPageView() });
            app.tabApp.Items.Add(shell_section);

            app.tabApp.Items.RemoveAt(0);

Basic Information

  • Version with issue:5.0.0.2012
  • Platform Target Frameworks:
  • iOS: 14.4
  • Android: 11
  • NuGet Packages: Xamarin Forms Visual Material, PancakeView,Essentials, CommunityToolkit,...
  • Affected Devices: iPhone X
@pablogupi pablogupi added s/unverified New report that has yet to be verified t/bug 🐛 labels Apr 11, 2021
@jsuarezruiz jsuarezruiz added a/shell 🐚 i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎 labels May 3, 2021
@jsuarezruiz jsuarezruiz removed the s/unverified New report that has yet to be verified label May 4, 2021
@MaxFelinger
Copy link

Having the same issue. Our TabItems change when another user does login (permission driven). Therefore we need to remove all Tabs on logout.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/shell 🐚 i/high Completely doesn't work, crashes, or is unusably slow, has no obvious workaround; occurs less often p/iOS 🍎 t/bug 🐛
Projects
None yet
Development

No branches or pull requests

3 participants