簡體   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