我添加了一个视图作为 ChildViewController,我只想在 ChildViewController 中关闭它并转到 Previous ViewController
来自 ParentViewController 的代码
@IBAction func click_monday(_ sender: Any) {
let blurEffect = UIBlurEffect(style: .regular)
let blurEffectView = UIVisualEffectView(effect: blurEffect)
blurEffectView.frame = self.view.bounds
blurEffectView.alpha = 0.8
view.addSubview(blurEffectView)
taskVC = self.storyboard?.instantiateViewController(withIdentifier: "Task") as! TaskVC
taskVC.view.backgroundColor = .clear
taskVC.modalPresentationStyle = .overCurrentContext
taskVC.preferredContentSize = CGSize(width: 550.0, height: 400.0)
self.view.addSubview(taskVC.view)
}
在 TaskVC 中,我有 SaveButton,它应该关闭该视图并返回到 ParentViewController(editVC)
我试过的是
@IBAction func click_save(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "edit") as! editVC
self.navigationController?.pushViewController(vc, animated: false)
}
但它不起作用:-(
尝试:
@IBAction func click_save(_ sender: Any) {
self.view.removeFromSuperview()
self.removeFromParentViewController()
//self.navigationController?.popViewController(animated: true) //Add this if necessary
}
另外,如果你想在同一个超级视图中删除另一个视图,你可以:
let blurView = self.view.superview?.viewWithTag(100) //assume that blurView's tag is set before by: blurView.tag = 100
blurView?.removeFromSuperview()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句