Search code examples
.netxamarinxamarin.iossplash-screen

Monotouch navigate from splash screen


I want to add a splash screen to a monotouch/xamarin project.

The splash screen should perform some logic and then navigate the user to one of two screens, logged in screen/Log in screen.

What is the correct way to do it in monotouch? (I am new to monotouch and IOS).


Solution

  • How i would do it, is something like this:

    1. Set your splash screen as the rootviewcontroller, do your logic in the background, and start to check if the user is logged in or not.
    2. Then on the async complete call, navigate the user to either logged in screen and set that as the new rootviewcontroller in a navigationcontroller. If the user is not logged in, push a topviewcontroller on top of the loggedinscreen - remember to check if the user is logged in or not, before you start loading user specific data in the logged in screen.

    Example:

            MySplashController splash;
            Navigationcontroller nav;
            UIViewController masterviewcontroller;
    
            Public override void FinishedLaunching(UIApplication app, NSDictionary options){
    
                  splash = new MySplashController();
                  window.rootviewcontroller = splash;
                  window.makekeyandvisible();
    
            }
            void MyAsyncLoggedInCall(bool loggedin){
               if(loggedin)
                 LoggedIn();
               else
                 LogOn();
            }
            void LoggedIn(){
             masterviewcontroller = MyLoggedInScreen();
             nav = new navigationcontroller(masterviewcontroller);
             window.rootviewcontroller = nav;
            }
            void LogOn(){
             masterviewcontroller = MyLoggedInScreen();
             nav = new navigationcontroller(masterviewcontroller);
             window.rootviewcontroller = nav;
             nav.TopViewController.PresentModalViewController(new MyLogInScreen(),false);
            }
    

    This is just one of the ways to do it. You can also look at how to implement the facebook login functions, and do something like that in your application, as its quite similar to your problem. Monotouch bindings