在动态框架中使用故事板

Use Storyboards in Dynamic Framework

我正在尝试在 swift 中创建一个动态框架。 我的框架在 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)

这样做我得到以下错误:

Attempt to present UIViewController: 0x135124920 on MyFramework.anotherViewController: 0x133df1a40 whose view is not in the window hierarchy!

self.pushviewController()self.show() 也不起作用。

我被这个问题卡了两天

我找到了让它工作的方法

在我使用我的框架的应用程序的 Appdelegate 中,我像这样传递了 rootviewcontroller 的实例:

test.myFunc(withRootView: (self.window?.rootViewController)!)

现在在我的框架中,我为它创建了一个 xib 和一个相应的 UIView 文件。 为了导航到这个 UIView 文件,我在 "myFunc" 函数中使用了下面的代码。

public func myFunc(withRootView rootview: UIViewController)
    let modalView = MyUIViewClass(frame: self.view.bounds)
     if rootview.presentedViewController == nil {
         rootview.view.addSubview(modalView)
     } else {
         rootview.presentedViewController?.view.addSubview(modalView)
     }