gpt4 book ai didi

ios - 点击 ParentViewController 关闭 ChildViewController

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

我有一个 ViewController,它有添加按钮,该按钮将在屏幕右侧打开 SideBarVC。如果我再次点击主 ViewController 屏幕,它应该关闭我的 SideBarVC。

我试过了

@IBAction func click_leistung(_ sender: UIButton) {

leistungList = self.storyboard?.instantiateViewController(withIdentifier: "leistungVC") as! leistungVC
leistungList.view.backgroundColor = .clear
leistungList.modalPresentationStyle = .overCurrentContext
self.present(leistungList, animated: true, completion: nil)

}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {


self.myscrollView.endEditing(false)
leistungList.removeFromParentViewController()
leistungList = nil
}

最佳答案

首先 - 你试图删除新的 VC,但你应该存储指向旧的 VC 的指针来删除它。创建 var 来存储指向此 leistungList 的指针,然后将其从父级中删除。

var storedController: UIViewController?
func show() {
// ...
storedController = presentedController
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

// Das keyboard ist weg
self.myscrollView.endEditing(false)
storedController.removeFromParentViewController()
storedController = nil
}

PS:阅读本文以了解如何管理子 Controller https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html

关于ios - 点击 ParentViewController 关闭 ChildViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44117126/

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