我无法继续,因为 Xcode 正在调用我的 Storyboard ID undeclared

I can't segue because Xcode is calling my Storyboard ID undeclared

在 iOS 上,即使我将 UserProfile 分配给 StoryboardId,为什么我仍会收到以下错误:

Use of undeclared type 'UserProfile'

这是我的代码:

let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)

 guard let destinationVC = mainStoryboard.instantiateViewController(withIdentifier: "UserProfile") as? UserProfile else {
            return
        }

 navigationController?.pushViewController(destinationVC, animated: true)
 guard let destinationVC = mainStoryboard.instantiateViewController(withIdentifier: "YourStoryBoardID") as? YourViewControllerClassName else {
            return
        }

as? YourViewControllerClassName 您需要在此处传递视图控制器的名称而不是故事板 ID。

更新:

由于您当前的视图控制器未嵌入到 navigationController 中,navigationController?.pushViewController 此 returns nil 并且该行未执行。要执行这一行,您的视图控制器应该有一个导航控制器。

将您的控制器嵌入到导航控制器中:Follow point no:1 ,2 ,3 here

如果不想使用navigationController,可以使用presentViewController代替。

guard let destinationVC = mainStoryboard.instantiateViewController(withIdentifier: "YourStoryBoardID") as? YourViewControllerClassName else {
            return
        }
self.present(destinationVC, animated: true, completion: nil)

Also learn about when to push and when to present a view controller