Sisyphus
Sisyphus

Reputation: 910

Xamarin.iOS: Black screen after launch screen when no storyboard

I don't want to use storyboard with my Xamarin.iOS app, so I did the following:

1- Deleted the storyboard files.

2- Updated the plist.info file Application > Main Interface to have no value.

3- Added the following code to the AppDelegate file.

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

But after doing this I received a black screen on the simulator after the launch screen finishes. This happens even with brand new projects. I have uploaded a sample new project with these steps and issue here.

I am using Visual Studio 2019 - Xamarion.iOS 11.8.3 - XCode 11.3.

I was using Visual Studio 2015 in the recent past with no problem, and I think that this issue happened only with Visual Studio 2019. Unfortunately, currently I don't have a Visual Studio 2015 to experiment with.

Upvotes: 1

Views: 1819

Answers (1)

nevermore
nevermore

Reputation: 15816

Start from iOS 13, the SceneDelegate is responsible for setting up the scenes of your app, move your codes from AppDelegate to 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();
}

Refer: Set rootViewController iOS 13 and The Scene Delegate In Xcode 11 And iOS 13

Upvotes: 7

Related Questions