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

Sis*_*hus 1 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;
}
Run Code Online (Sandbox Code Playgroud)

但是在这样做之后,我在启动屏幕完成后在模拟器上收到了一个黑屏。即使是全新的项目也会发生这种情况。我已上载这些步骤和问题的样本新的项目在这里

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

我最近在使用 Visual Studio 2015 没有问题,我认为这个问题只发生在 Visual Studio 2019 上。不幸的是,目前我没有 Visual Studio 2015 可以试验。

Jac*_*Hua 7

从 iOS 13 开始,SceneDelegate负责设置您的应用程序的场景,将您的代码从 移动AppDelegateSceneDelegate

[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();
}
Run Code Online (Sandbox Code Playgroud)

参考:在 Xcode 11 和 iOS 13 中设置 rootViewController iOS 13场景委托