This repository was archived by the owner on May 1, 2024. It is now read-only.
This repository was archived by the owner on May 1, 2024. It is now read-only.
[Bug] [iOS] [Shell] NullReferenceException when remove tab programmatically #14142
Open
Description
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
- In AppShell.xml create a empty TabBar
<TabBar x:Name="tabApp"/ >
- 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);
- 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