无法实例化视图控制器。 -斯威夫特

问题描述 投票:0回答:1

所以,我试图使用情节提要引用以编程方式实例化我的视图控制器。

我已将此代码放入AppDelegate:

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    window = UIWindow(frame: UIScreen.main.bounds)

    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let initialController: WelcomePageViewController = mainStoryboard.instantiateViewController(withIdentifier: "WelcomePageViewController") as! UITabBarController
        window?.rootViewController = initialController        
    window?.makeKeyAndVisible()
    return true
}

并将其设置在我的视图控制器的故事板上:

Storyboard screenshot

但是,当我运行该应用程序时,仅显示黑屏,并显示以下消息:“无法实例化UIMainStoryboardFile'Main'的默认视图控制器-也许未设置指定的入口点?”

我已经在其他应用程序中使用了这个确切的代码,并且很好用。

我试图清理构建文件夹,在实际设备上运行它,并创建和实例化一个不同的故事板文件,但无济于事。

ios swift xcode storyboard
1个回答
0
投票

打开Main.storyboard文件并找到WelcomePageViewController。选中后,转到属性检查器,然后选中标记为Is Initial View Controller的框。

[您应该看到WelcomePageViewController的左侧出现一个向右的箭头,表明它是情节提要的入口点。

现在你们都准备出发了!

© www.soinside.com 2019 - 2024. All rights reserved.