【发布时间】:2026-02-22 16:05:02
【问题描述】:
我将PlannerViewController 附加到我的Main.storyboard。当我构建并运行应用程序时,我收到以下错误:
Storyboard (<NSStoryboard: 0x608000001790>) doesn't contain a controller with identifier 'PlannerViewController'
在 Main.storyboard 中,我确实将 PlannerViewController 设置为自定义类和故事板 ID。这是 PlannerViewController.swift 中的代码:
import Cocoa
class PlannerViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
}
}
extension PlannerViewController {
// MARK: Storyboard instantiation
static func freshController() -> PlannerViewController {
let storyboard = NSStoryboard(name: "Main", bundle: nil)
guard let viewcontroller = storyboard.instantiateController(withIdentifier: "PlannerViewController") as? PlannerViewController else {
fatalError("Why cant i find QuotesViewController? - Check Main.storyboard")
}
return viewcontroller
}
}
有谁知道如何解决这个错误?
请注意,我使用的是 Swift 3,而且我是 Swift 新手。
谢谢。
编辑:顺便说一句,我正在关注this tutorial 开发一个菜单栏应用程序。
【问题讨论】:
-
你添加一个标识符“PlannerViewController”到故事板上的视图控制器吗?
-
当我添加
let identifier = NSStoryboard.SceneIdentifier(rawValue: "QuotesViewController")我得到这个错误:NSStoryboard has no member 'SceneIdentifier'。