Atlantis Atlantis - 9 days ago 8
C# Question

Xamarin Forms change mainpage ios error

I use Xamarin.Forms MasterDetailPage and ContentPage with Navigataion.
When app is started I call LoginPage

Application.Current.MainPage = new NavigationPage(new LoginInPage());


Then logging in is success I call MasterDetailPage

App.Current.MainPage = new RootPage();
await Navigation.PopToRootAsync();


In Android all work is well, but in iOS simulator has error


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


in Main.cs on ios

UIApplication.Main(args, null, "AppDelegate");

Answer

It's work.

 if (Device.OS == TargetPlatform.Android)
                    Application.Current.MainPage = new Source.Pages.MenuPage();
                else if (Device.OS == TargetPlatform.iOS)
                    await Navigation.PushModalAsync(new Source.Pages.MenuPage());
Comments