You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xcode 11.2 iOS Simulator启动黑屏问题求助

Troubleshooting iOS Black Screen After Removing Storyboard Segues (No Error Logs)

Hey there, let’s dig into this frustrating black screen issue you’re dealing with. It’s tricky when there are no error logs to guide you, but let’s break down the most likely culprits step by step—these are the fixes that usually resolve this kind of problem.

1. Double-Check Your Initial View Controller Setup

Even after commenting out your segue code, modifying Storyboard-related logic often messes up how your app’s first screen is loaded. Here’s what to verify:

  • Info.plist Configuration: Open your Info.plist and look for the UIMainStoryboardFile key. If you were moving away from Storyboards, did you remove this key? If you’re still using a Storyboard, ensure the initial view controller is still marked with the checkmark in the Storyboard editor.
  • Programmatic Root VC Setup: For iOS 13+, your SceneDelegate.swift is responsible for setting the root view controller. Make sure you didn’t miss critical lines like window.makeKeyAndVisible(). Example of correct setup:
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
        let window = UIWindow(windowScene: windowScene)
        // Ensure your VC is initialized properly (use init(nibName:) if it has a xib)
        let initialVC = ViewController()
        window.rootViewController = initialVC
        self.window = window
        window.makeKeyAndVisible() // This line is easy to forget!
    }
    
    Common mistake: Skipping window.makeKeyAndVisible() leaves your window hidden, resulting in a black screen.

2. Verify View Controller Initialization

If you’re instantiating VCs programmatically, small missteps here can cause blank screens:

  • If your view controller uses a xib file, don’t use the default ViewController() initializer—you need to call ViewController(nibName: "ViewController", bundle: nil) to load the xib correctly. Using the empty init will create a VC with a blank view.
  • Add a print statement in viewDidLoad() (like print("Initial VC loaded!")) to confirm the VC is actually being initialized. If this doesn’t show up in the console, your root VC isn’t being set properly at all.

3. Check for Accidental View Configurations

Sometimes tiny, overlooked settings can hide your view:

  • In your initial VC’s viewDidLoad or viewWillAppear, make sure you didn’t accidentally set self.view.isHidden = true or self.view.alpha = 0.0.
  • If using auto layout, confirm your main view has constraints pinning it to all edges of the window. Missing constraints can push your view off-screen, making it look like a black screen.

4. Clean Up Build Artifacts (Beyond Simulator Data)

You tried clearing simulator data, but leftover build files can cause weird, persistent issues:

  • Go to Product > Clean Build Folder (shortcut: Shift + Command + K) in Xcode.
  • Delete Derived Data: Open Xcode > Settings > Locations > Derived Data, click the arrow next to the path, and delete the folder for your project.
  • Rebuild and run the app again—this wipes out any cached files that might be causing conflicts.

5. Test on a Physical Device (If You Can)

Occasionally simulator-specific bugs cause black screens that don’t show up on real devices. Running your app on an iPhone or iPad can help you rule out whether this is a simulator quirk or a real code issue.

6. Hunt for Unintended Code Changes

Even if you commented out the segue code, it’s easy to accidentally tweak other parts of your project:

  • Check your target’s build settings: Go to Target > Build Settings > Swift Compiler - General > Main Interface and ensure it’s set correctly (either your Storyboard name or blank if you’re doing full programmatic setup).
  • Scan AppDelegate or SceneDelegate for any code that might be overriding the root VC later in the app lifecycle (like in applicationDidBecomeActive).

If you can share snippets of your SceneDelegate setup or the segue code you were trying to implement, that would help narrow things down even more!

内容的提问来源于stack exchange,提问作者user12329049

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 09:07:12