2

I went through most of the MvvmCross tutorials and I thought I was ready to start my first iOS project. However I got stuck within the first hour of trying to implement the navigation structure.

Here's what I'm trying to achieve:

1) When the app first loads, it needs to show a Splash screen with Sign in and Sign up buttons. 2) Only after signing in or signing up the user can go to the main view.

I tried to do this using a command in the view model like:

//authentication code here...

ShowViewModel<MainViewModel>();

The problem with this is that when it navigates to the main view, the user is able to press the back button at the top and go back to the sign in screen and then go back to the splash screen by pressing the back button again.

The solution I found was to use the MainView as the start up view and the Splash screen should be a panel on top of it that becomes invisible when the user is authenticated. But I don't know if this is the common practice for this scenario.

Thanks!

2 Answers 2

2

You can go into your App class and change the view model that's loaded once the app starts up.

public class App : Cirrious.MvvmCross.ViewModels.MvxApplication
{
    public override void Initialize()
    {
        CreatableTypes()
            .EndingWith("Service")
            .AsInterfaces()
            .RegisterAsLazySingleton();

        Globals.Init().Wait();

        if (Globals.HasCredentials())
        {
            RegisterAppStart<ViewModels.DispatchListViewModel>();
        }
        else
        {
            RegisterAppStart<ViewModels.WelcomeViewModel>();
        }
    }
}
1
  • It's just a class in my app. It has nothing to do with MvvmCross.
    – Alexey
    Jan 30, 2014 at 0:34
0

If you're using a UINavigationController, you could pop the splash screen off the view stack using:

NavigationController.PopViewControllerAnimated(true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.