我是SWIFT世界的新手,我已经创建了一个非常基本的应用程序,可以从一个名为Main
的故事板控制器加载3个视图
@IBAction func view2ButtonClicked(_ sender: Any) {
if let vc = self.storyboard?.instantiateViewController(withIdentifier: String(describing: Test2ViewController.self)) as? Test2ViewController {
self.navigationController?.pushViewController(vc, animated: true)
}
}
@IBAction func view3ButtonClicked(_ sender: Any) {
if let vc = self.storyboard?.instantiateViewController(withIdentifier: String(describing: Test3ViewController.self)) as? Test3ViewController {
self.navigationController?.pushViewController(vc, animated: true)
}
}
然而,我也复制了一个.h
&;.m
以及一个较老的obj-c
项目的情节提要,我已经设置了桥接头,我正在try 使用以下方法加载它;
@IBAction func view1ButtonClicked(_ sender: Any) {
let storyboard = UIStoryboard(name: "CompassView", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "CompassViewController")
self.navigationController!.pushViewController(vc, animated: true)
}
然而,它与错误一起崩溃;
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Could not find a storyboard named 'CompassView' in bundle NSBundle
当我找到Compass情节提要文件时,我判断了它的名称,发现它是Compass.storyboard
自定义类为CompassViewController
,情节提要ID为CompassView