gpt4 book ai didi

ios - 在 ChildViewController 中关闭 ChildViewController 并转到上一个 ViewController

转载 作者:行者123 更新时间:2023-11-30 12:23:10 25 4
gpt4 key购买 nike

我已添加一个 View 作为 ChildViewcontroller,并且我只想在 ChildViewController 中关闭它并转到上一个 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,它应该关闭该 View 并返回到 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
}

此外,如果您想删除同一 super View 中的另一个 View ,您可以:

let blurView = self.view.superview?.viewWithTag(100)  //assume that blurView's tag is set before by: blurView.tag = 100 
blurView?.removeFromSuperview()

关于ios - 在 ChildViewController 中关闭 ChildViewController 并转到上一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44543194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com