在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)
三个都没有理想的结果。第一个从笔尖移除按钮,第二个按钮给我一个黑屏,第三个关闭导航视图中将笔尖嵌入到原始视图的视图。
我在类级别将svc声明为var,并且能够使用
self.v.removeFromSuperview()
这对我有用。