Xamarin.iOS:没有情节提要时启动屏幕后出现黑屏

时间:2020-01-12 08:43:12

标签: c# ios xamarin

我不想在Xamarin.iOS应用中使用情节提要,所以我做了以下事情:

1-删除情节提要文件。

2-将plist.info文件“应用程序”>“主界面”更新为没有值。

3-将以下代码添加到AppDelegate文件中。

[Export ("application:didFinishLaunchingWithOptions:")]
public bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
    // create a new window instance based on the screen size
    Window = new UIWindow(UIScreen.MainScreen.Bounds);

    var controller = new UIViewController();
    controller.View.BackgroundColor = UIColor.LightGray;
    controller.Title = "My Controller";

    var navController = new UINavigationController(controller);

    Window.RootViewController = navController;

    // make the window visible
    Window.MakeKeyAndVisible();

    return true;
}

但是这样做之后,启动屏幕结束后,我在模拟器上收到了黑屏。即使是全新项目,也会发生这种情况。我已通过以下步骤上传了一个示例新项目,并发出了here

我正在使用Visual Studio 2019-Xamarion.iOS 11.8.3-XCode 11.3。

我最近在使用Visual Studio 2015没问题,并且我认为该问题仅在Visual Studio 2019中发生。不幸的是,目前我没有Visual Studio 2015试用。

1 个答案:

答案 0 :(得分:6)

从iOS 13开始,SceneDelegate负责设置应用程序的场景,将代码从AppDelegate移至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 controller = new UIViewController();
    controller.View.BackgroundColor = UIColor.LightGray;
    controller.Title = "My Controller";

    UINavigationController navigationMain = new UINavigationController(controller);
    Window.RootViewController = navigationMain;
    Window.MakeKeyAndVisible();
}

引用:Set rootViewController iOS 13The Scene Delegate In Xcode 11 And iOS 13