【发布时间】:2018-09-26 11:05:26
【问题描述】:
我正在尝试快速创建一个动态框架。 我的框架在 Storyboard 中包含一个 ViewController。 当推送通知进入我的框架时,我无法打开我的 ViewController。 但是我尝试使用以下代码:
let bundle = Bundle(identifier: "my_Framework_bundleID")
let frameworkStoryboard: UIStoryboard = UIStoryboard.init(name: "MyFrameworkStoryboard", bundle: bundle)
let viewController = frameworkStoryboard.instantiateViewController(withIdentifier: "MyViewController")
self.present(viewController, animated: true, completion: nil)
这样做只会执行 MyViewController 的 viewDidLoad 方法中的代码,但不会显示 UI 的负载。
我也试过这个:
let bundle = Bundle(identifier: "my_Framework_bundleID")
let controller = UIViewController(nibName: "MyViewController", bundle: bundle)
present(controller, animated: true, completion: nil)
这样做我得到以下错误:
尝试在 MyFramework.anotherViewController: 0x133df1a40 上呈现 UIViewController: 0x135124920,其视图不在窗口层次结构中!
self.pushviewController() 和 self.show() 也不能正常工作。
我被这个问题困了两天。
【问题讨论】:
-
您在哪里调用该代码
-
如果在 viewController 中运行,您可能需要在主线程中运行。 DispatchQueue.main.async{self.present(viewController, animated: true, completion: nil) }
-
找出解决方案。感谢 Sh_Khan 和 E.Coms 的帮助
标签: ios swift frameworks storyboard viewcontroller