gpt4 book ai didi

ios - 访问 Cocoa 框架 Storyboard

转载 作者:行者123 更新时间:2023-11-28 08:26:06 25 4
gpt4 key购买 nike

我有带有两个 Controller 类和 Storyboard的 Swift Cocoa Touch 框架。当我尝试 instantiateViewController 从一个类到另一个类时,它不起作用,它显示 Storyboard不可见。

我可以使用以下方法从基础项目启动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)
}

enter image description here

我想在单击第一个 View Controller 时实例化第二个 View Controller 。现在我正在使用此代码块进行启动,但它不起作用。

 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)
}

最佳答案

最后,我找到了解决问题的办法。

@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 中,必须添加上面的代码块。

关于ios - 访问 Cocoa 框架 Storyboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39950945/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com