在Swift 4 X Code 9中,如果按如下方式加载并显示Nib,如何解除它?

问题描述 投票:0回答:1

在Swift 4 X Code 9中,如果按如下方式加载并显示Nib,如何解除它?这是我的代码在另一个ViewController中的提取,Nib从中加载。

 @objc func doPresent(_ sender: Any?) {
    if let svc = Bundle.main.loadNibNamed("SecondViewController", owner: self, options: nil)?.first as? SecondViewController {
    svc.data = "This is very important data!"
    svc.delegate = self
    self.present(svc, animated:true)
    }
  }

我试过了:

self.view.subviews[0].removeFromSuperview()

self.view.removeFromSuperview()

以及

self.dismiss(animated:true)

三者中没有一个具有期望的结果。第一个从Nib中删除一个按钮,第二个只给我一个黑屏,第三个删除了Nib嵌入到导航视图中原始视图的视图。谢谢

ios11 swift4
1个回答
0
投票

我在类级别将svc声明为var并且能够使用

self.v.removeFromSuperview()

这对我来说很有把戏。

© www.soinside.com 2019 - 2024. All rights reserved.