简体   繁体   English

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

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

I am creating an application using xamarin.ios.我正在使用 xamarin.ios 创建一个应用程序。 I have some pages in my storyboard and I have set "Is initial View Controller" for one of the pages as the first page.我的故事板中有一些页面,并且我已将其中一个页面的“是初始视图控制器”设置为第一页。 Users see that page as the first page if they already logged in otherwise I want to show the login page.如果用户已经登录,则将该页面视为第一页,否则我想显示登录页面。 To do that I added this code:为此,我添加了以下代码:

        [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;
        }

The problem is, this code cannot change the first page at all.问题是,此代码根本无法更改第一页。 It seems my application always ignore this code and shows the page with "Is Initial View controller" equals true on storyboard.似乎我的应用程序总是忽略此代码,并在情节提要上显示“Is Initial View controller”等于 true 的页面。 It means when I change first page on storyboard I see the change but no change when I set it in my code.这意味着当我更改故事板上的第一页时,我会看到更改但在我的代码中设置它时没有更改。

The app delegate's role changes from iOS 12 to iOS 13, the SceneDelegate is responsible for setting up the scenes of your app :应用委托的角色从 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();
}

Here are some threads about this question in swift: set-rootviewcontroller-ios-13 and ios-13-swift-set-application-root-view这里有一些关于这个问题的 swift 线程: set-rootviewcontroller-ios-13ios-13-swift-set-application-root-view

And articles: accessing-root-view-controller-ios13-scenedelegate and scene-delegate-app-delegate-xcode-11-ios-13和文章: 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