【问题标题】:Access Cocoa framework storyboard访问 Cocoa 框架故事板
【发布时间】:2016-10-10 17:26:35
【问题描述】:

我有两个控制器类和情节提要的 Swift Cocoa Touch 框架。当我尝试instantiateViewController 从一个班级到另一个班级时,它不起作用,它显示故事板不可见。

我可以使用以下方法从基础项目启动 test.storyboard

 if let urlString = Bundle.main.path(forResource: "testProject", ofType: "framework", inDirectory: "Frameworks") {
            let bundle = (Bundle(url: NSURL(fileURLWithPath: urlString) as URL))
            let sb = UIStoryboard(name: "test", bundle: bundle)
            let vc = sb.instantiateViewController(withIdentifier: "TestViewcontroller")
            self.show(vc, sender: nil)
 }

我想在第一个按钮单击时实例化第二个视图控制器。现在我正在使用这个代码块来启动,但它不起作用。

 if let urlString =  Bundle.main.path(forResource: "testProject", ofType: "framework", inDirectory: "Frameworks") {
            let bundle = (Bundle(url: NSURL(fileURLWithPath: urlString) as URL))
            let secondvc = UIStoryboard(name: "test", bundle: bundle).instantiateViewController(withIdentifier: "secondViewc") as! secondcontroller

            self.show(secondvc, sender: nil)
 }

【问题讨论】:

    标签: ios swift cocoa-touch


    【解决方案1】:

    最后,我找到了问题的解决方案。

    @IBAction func back(_ sender: AnyObject) {
         let frameworkBundle = Bundle(for: Maincontroller.self)
         let secondvc = UIStoryboard(name: "test", bundle: frameworkBundle).instantiateViewController(withIdentifier: "secondViewc") as! secondcontroller
         self.present(secondvc, animated: true, completion: nil)
    }
    

    在 testProject -> Maincontroller.swift 里面,必须添加上面的代码块。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多