You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从Demo项目调用Framework中Storyboard视图控制器报错求助

解决「Could not find a storyboard named 'checkoAuthFrameworkStoryBoard' in bundle」问题

1. 核对编译后Storyboard的实际文件名

编译后的Storyboard会被打包成后缀为.storyboardc的文件夹,你需要:

  • 严格比对截图里的实际文件名和代码中checkoAuthFrameworkStoryBoard的大小写、拼写是否完全一致(iOS系统下文件名区分大小写)
  • 检查Framework项目的Build Phases -> Copy Bundle Resources,确认该Storyboard已被添加,保证它会被打包进Framework的bundle中

2. 修正Bundle获取逻辑

通过Bundle identifier获取可能存在加载偏差,建议换更可靠的方式获取Framework的bundle:

// 替换原有的Bundle(identifier:)写法
if let frameworkBundlePath = Bundle.main.path(forResource: "checkoAuthFramework", ofType: "framework"),
   let bundle = Bundle(path: frameworkBundlePath) {
    MyFrameworkCoordinator.instantiateFrameworkStoryboard(controller: self, bundle: bundle)
}

更推荐在Framework内部封装bundle获取方法,避免外部依赖identifier:

public class MyFrameworkCoordinator {
    // 封装Framework自身的bundle获取
    public static var frameworkBundle: Bundle {
        return Bundle(for: self)
    }
    
    public static func instantiateFrameworkStoryboard(controller: UIViewController) {
        let storyboard = UIStoryboard(name: "checkoAuthFrameworkStoryBoard", bundle: frameworkBundle)
        let scanVC = storyboard.instantiateViewController(withIdentifier: "ScanViewController") as! ScanViewController
        
        controller.present(scanVC, animated: true)
    }
}

外部调用可简化为:

MyFrameworkCoordinator.instantiateFrameworkStoryboard(controller: self)

3. 检查Storyboard的Target归属

在Framework项目中选中该Storyboard文件,查看右侧Inspector面板的Target Membership,确保已勾选你的Framework target——未勾选的话,文件不会被包含到编译后的Framework中。

4. 修正代码中的小问题

你当前的present代码多了.self,会引发后续运行时错误,建议修正:

controller.present(scanVC, animated: true, completion: nil)

内容的提问来源于stack exchange,提问作者BinaryDiv

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 05:39:52