无法在iOS 13中更改Main.storyboard的名称 [Xcode 11 GM Seed 2]

7
在使用Xcode 11 GM种子版本2的iOS 13模拟器上,当Main.storyboard的名称更改(Info.plist也更改)后,应用程序会崩溃。将选项 Main Interface 设置为空会导致相同的问题。iOS 13系统始终会尝试查找Main.storyboard,并在崩溃消息中失败。
*** reason: 'Could not find a storyboard named 'Main' in bundle

iOS 12及以前版本运行一切正常。看起来这是iOS 13中的一个bug。

是否有其他人遇到了相同问题?有解决方案吗?


也要在 info.plist 文件中进行更改。 - Orkhan Alikhanov
你确定这个文件已经包含在构建中了吗? - Orkhan Alikhanov
@OrkhanAlikhanov,所有操作都很好,因为该应用程序正在运行iOS 12上。 - Yun CHEN
如果您将其重新命名为“Main.storyboard”,那么它是否能够正常工作? - Nirav Kotecha
@NiravKotecha,是的。 - Yun CHEN
3个回答

22

使用 iOS 13 的 Swift 5

应用场景清单(Application Scene Manifest)组下,需要进行一次更改,修改info.plist文件。

输入图像描述

同时也要在应用场景清单(Application Scene Manifest)中更改名称。

附加:
如果您想在iOS13上不使用故事板(storyboard)创建根窗口,需要从Info.plist中删除Main storyboard file base nameStoryboard Name项目,然后在SceneDelegate中通过编程方式创建窗口。

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        if #available(iOS 13.0, *) {
            //Do nothing here
        } else {
            window = UIWindow(frame: UIScreen.main.bounds)
            window?.makeKeyAndVisible()
        }

        return true
    }
}

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

    var window: UIWindow?

    @available(iOS 13.0, *)
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.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 `application:configurationForConnectingSceneSession` instead).
        guard let windowScene = (scene as? UIWindowScene) else { return }
        window = UIWindow(windowScene: windowScene)
        // continue to create view controllers for window
    }

    //......
}

我尝试更改两个出现的位置(如此答案所说),但是仍然不起作用:它在@UIApplicationMain处崩溃。我放弃了。 - Nicolas Miari
@NicolasMiari,我更新了编程方式的答案,请查看。 - Yun CHEN

0

在将Main.storyboard的名称更改后,将Main storyboard file base nameInfo.plist中更改。当然,您也可以从General-Deployment info-Main Interface更改它。


问题出现在你所提到的正确操作上。 - Yun CHEN

0

Xcode 重命名 Main.storyboard

只需在 Info.plist 文件中将 UISceneStoryboardFile 字符串重命名为正确的名称即可。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接