【问题标题】:Not able to present a viewController which is inside Framework无法呈现框架内的 viewController
【发布时间】:2019-02-20 20:25:27
【问题描述】:

我正面临一个严重的问题。我有一个名为“abc.framework”的框架,它包含一个函数,您可以在其中传递一个 viewController 对象。

//this is the method in my framework 

func launchView(view:UIViewController){

}

//this is what needs to be written on App side

myFrameworkFile.launchView(view: self)

上述方法用于在传递的 viewController 对象之上呈现 Framework 的 viewController 即 abc.framework viewController。启动方法包含以下代码:

func launchView(view:UIViewController)
{


var rootController: UIViewController?

    rootController = view

    let storyboard = UIStoryboard(name: "abcFrameworkBundle.bundle/abcUIMain", bundle: nil)
    let VC1 = storyboard.instantiateViewController(withIdentifier: "selectedviewcontroller") as! SelectedViewController

    rootController?.present(VC1, animated: true, completion: nil)
}

从上面的方法中,viewController 的 SelectedViewController viewDidLoad 方法被调用,但是它没有被呈现,我收到以下警告

警告:尝试在 其视图不在窗口层次结构中!

有人遇到过同样的问题吗?

【问题讨论】:

  • this 会帮助你吗?无论如何,我会在你的框架类中创建静态方法,它会返回我的控制器实例。那么你可以在你的项目中做let controller = SomeClass.instantiate(); present(controller, animated: true)
  • 你在哪里调用这个方法“launchView”?

标签: ios swift frameworks


【解决方案1】:

我猜你在viewDidLoad 或更早的时候调用了这个方法myFrameworkFile.launchView(view: self)。尝试将其移入viewDidAppear

【讨论】:

    猜你喜欢
    • 2018-03-08
    • 1970-01-01
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 2018-03-07
    • 2012-05-22
    • 1970-01-01
    相关资源
    最近更新 更多