Monotouch替换RootViewController

时间:2013-05-09 22:22:20

标签: iphone xamarin.ios xamarin monotouch.dialog

使用MonoTouch我将一个LogonViewController添加到Window并在FinishedLaunching上显示:

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

LogonViewController 中,如何添加名为 MainViewContoller 的主VC并删除 LogonViewController ? (这是用户登录后将发生的操作。)

2 个答案:

答案 0 :(得分:6)

即使可以替换window.RootViewController,也不是通常的方式。大多数情况下,您定义RootViewController并从那里处理导航,包括登录。至少我是这样做的。

//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, ()=>{});
}

答案 1 :(得分:5)

这是我的价值,这是我以前做过的。

public static void swapRootView(UIViewController newView, UIViewAnimationOptions opt)
        {
            UIView.Transition(mainWindow, 0.5, opt, delegate{
                mainWindow.RootViewController = newView;

            },null);
        }

登录完成后,使用此选项调用该方法。

swapRootView(yourNewViewController, UIViewAnimationOptions.TransitionFlipFromRight);
相关问题