在Swift 4 Xcode 9中,如果按以下方式加载并显示Nib,如何将其关闭?

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

在Swift 4 Xcode 9中,如果您按如下方式加载和显示Nib,如何将其关闭?这是我在另一个加载了Nib的ViewController中的代码的摘录。

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

三个都没有理想的结果。第一个从笔尖移除按钮,第二个按钮给我一个黑屏,第三个关闭导航视图中将笔尖嵌入到原始视图的视图。

ios11 swift4
1个回答
0
投票

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

self.v.removeFromSuperview()

这对我有用。

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