我已将视图添加为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,该按钮应关闭该视图并返回到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()

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

10-12 04:08