繁体   English   中英

Xamarin.ios 登录页面,无法更改故事板的第一页

[英]Xamarin.ios login page, cannot change the first page of storyboard

我正在使用 xamarin.ios 创建一个应用程序。 我的故事板中有一些页面,并且我已将其中一个页面的“是初始视图控制器”设置为第一页。 如果用户已经登录,则将该页面视为第一页,否则我想显示登录页面。 为此,我添加了以下代码:

        [Export ("application:didFinishLaunchingWithOptions:")]
        public bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
        {
            this.Window = new UIWindow(UIScreen.MainScreen.Bounds);
            LoginViewController yourViewController = UIStoryboard.FromName("Main", NSBundle.MainBundle).InstantiateViewController("LoginViewController") as LoginViewController;

            this.Window.RootViewController = yourViewController;
            this.Window.MakeKeyAndVisible();
            return true;
        }

问题是,此代码根本无法更改第一页。 似乎我的应用程序总是忽略此代码,并在情节提要上显示“Is Initial View controller”等于 true 的页面。 这意味着当我更改故事板上的第一页时,我会看到更改但在我的代码中设置它时没有更改。

应用委托的角色从 iOS 12 到 iOS 13, SceneDelegate负责设置您的应用的场景:

[Export ("scene:willConnectToSession:options:")]
public void WillConnect (UIScene scene, UISceneSession session, UISceneConnectionOptions connectionOptions)
{
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see UIApplicationDelegate `GetConfiguration` instead).

    UIWindowScene myScene = scene as UIWindowScene;
    Window = new UIWindow(myScene);
    UIViewController viewController = new UIViewController();
    UINavigationController navigationMain = new UINavigationController(viewController );
    Window.RootViewController = navigationMain;
    Window.MakeKeyAndVisible();
}

这里有一些关于这个问题的 swift 线程: set-rootviewcontroller-ios-13ios-13-swift-set-application-root-view

和文章: accessing-root-view-controller-ios13-scenedelegatescene-delegate-app-delegate-xcode-11-ios-13

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM