Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monotouch Replacing the RootViewController

Using MonoTouch I add a LogonViewController to the Window and show it on FinishedLaunching:

        window = new UIWindow(UIScreen.MainScreen.Bounds);
        window.RootViewController = new LogonViewController();
        window.MakeKeyAndVisible();

In the LogonViewController, how do I add the main VC, called MainViewContoller and remove the LogonViewController? (This is the action that will happen once the user is logged in.)

like image 377
Ian Vink Avatar asked Aug 11 '26 12:08

Ian Vink


1 Answers

Even if it's possible to replace the window.RootViewController, that's not how it's usually done. Most of the time, you define your RootViewController and handle your navigation, including login, from there. That's at least how I do it.

//AppDelegate.cs
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
    window = new UIWindow (UIScreen.MainScreen.Bounds);
    window.RootViewController = new MainViewController ();      
    window.MakeKeyAndVisible ();
    return true;
}

//MainViewController.cs
public override void ViewDidLoad ()
{
    base.ViewDidLoad ();
    if (not_logged_in)
        PresentViewController (new LoginViewController (), true, ()=>{});
}
like image 143
Stephane Delcroix Avatar answered Aug 13 '26 03:08

Stephane Delcroix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!