我是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

推荐答案

当我找到Compass情节提要文件时,我判断了它的名称,发现它是Compass.storyboard

那么你应该像这样加载它

let storyboard = UIStoryboard(name: "Compass", bundle: nil)

Ios相关问答推荐

设置堆栈视图的所有属性

底部导航栏在iOS上浮动

以编程方式更改VC&39;S导航栏按钮的属性,以响应另一个VC中的按钮按下

自定义UIControl不适用于UITapGestureRecognizer

使用标头UICollectionViewFlowLayout时的简单SwiftUI视图错误

在将Cocoapods更新到1.13.0之后,它抛出错误

BezierPath 中绘制图像形状轮廓的算法(Canny 边缘检测器)

如何在集合视图中创建装饰视图?

帧过渡动画有条件地工作

通过函数使用 Gesture 时,键入任何视图不能符合视图

JSONDecoder 在模拟器上运行良好时无法在真实设备上解码

UILabel - 字符串作为文本和链接

改变 UIView 位置的简单方法?

iOS:使用 UIView 的 'drawRect:' 与其层的委托 'drawLayer:inContext:'

iOS Swift - 获取当前本地时间和日期时间戳

Sierra 中的安全/协同设计: keys 串忽略访问控制设置和 UI 提示权限

Storyboard Segue 从视图控制器到自身

有没有办法在应用store 之外分发 ios 应用程序?

如何在 Android 和 iPhone 的移动应用程序中实施推荐计划

Twitter api 文本字段值被截断