gpt4 book ai didi

ios - 从最后一个推送几个 ViewControllers 和触发方法,取消之前的所有

转载 作者:搜寻专家 更新时间:2023-10-31 22:12:36 25 4
gpt4 key购买 nike

这是我的问题。

我有 ViewController A(我们只称它为 A)。
我从A 推送到B,这是自定义相机 Controller 。当我拍照时,我会模态显示 Controller C,它有两个按钮,一个用于确认,一个用于返回。
如果点击后退按钮,它会返回到 B Controller 。
如果点击确认按钮,C 应该触发对A 的委托(delegate)方法,然后关闭CB,但没有动画,所以关闭 B 不会被注意到。

问题:
1. 如何实现上述场景? A 需要委托(delegate)给C,那怎么办呢?我还应该使用展开吗?

提醒:A -> 推送 -> B -> 模态 -> C

最佳答案

我认为你可以通过将 B 的引用传递给 C Controller 来实现相同的功能

Controller B代码

class BViewController: UIViewController {

weak var controllerA : ViewController!

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func confirmEventCallFromC() {
self.navigationController?.popViewController(animated: false)
}

@IBAction func btnClick(_ sender: Any) {
self.performSegue(withIdentifier: "CVC", sender: nil)
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "CVC" {
let vc = segue.destination as! CViewController
vc.controllerB = self
}

}

}

Controller C代码是这样的

class CViewController: UIViewController {

weak var controllerB : BViewController!

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

@IBAction func confirmBtnClick(_ sender: Any) {
controllerB.confirmEventCallFromC()
self.dismiss(animated: true, completion: nil)
}

}

希望对您有所帮助。

关于ios - 从最后一个推送几个 ViewControllers 和触发方法,取消之前的所有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40929423/

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