gpt4 book ai didi

ios - 在具有委托(delegate)的多个 UIViewController 队列上使用解雇 View Controller

转载 作者:行者123 更新时间:2023-11-30 13:39:19 25 4
gpt4 key购买 nike

当我的应用程序第一次启动时,我将展示 4 UIViewController 的教程。每个 UIViewController 都有一个带有显示下一个 ViewController 的 segue 的 Button。最后一个 ViewController 有一个“让我们开始”按钮,它应该完全关闭教程。

问题:这将关闭除第一个之外的所有 ViewController。我不明白为什么?!

我的期望:

在最后一个ViewController4上,我调用第一个ViewController的dismissIntroduction()函数,所以除了所有ViewController(包括ViewController1)之外的所有ViewController都应该消失。当我在第一个 ViewController 上放置一个按钮并调用函数“dismissIntroduction()”时,它就会消失。

ViewController 1(WelcomeViewController):

protocol WelcomeViewDelegate {
func dismissIntroduction()
}

class WelcomeViewController: UIViewController, WelcomeViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()

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

func dismissIntroduction() {
self.dismissViewControllerAnimated(true, completion: nil)
}


// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destination = segue.destinationViewController as! ViewController2
destination.delegate = self
}

}

ViewController 2:

class ViewController2: UIViewController {

var delegate:WelcomeViewDelegate?

override func viewDidLoad() {
super.viewDidLoad()
}

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destination = segue.destinationViewController as! ViewController3
destination.delegate = self.delegate
}

}

ViewController 3:

class ViewController3: UIViewController {

var delegate:WelcomeViewDelegate?

override func viewDidLoad() {
super.viewDidLoad()
}

// MARK: - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destination = segue.destinationViewController as! ViewController4
destination.delegate = self.delegate
}

}

ViewController4(最后一个):

class ViewController4: UIViewController {

var delegate:WelcomeViewDelegate?

override func viewDidLoad() {
super.viewDidLoad()
}

@IBAction func pressLetsStart(sender: AnyObject) {
self.delegate!.dismissIntroduction()
}

}

编辑:当我两次放置missViewControllerAnimated函数时,我得到了它的工作!?

func dismissIntroduction() {
self.dismissViewControllerAnimated(true, completion: nil)
self.dismissViewControllerAnimated(true, completion: nil)
}

但是为什么呢?我不明白背后的逻辑...

最佳答案

您正在寻找错误的问题解决方案,您需要做的是寻找 Unwind Segues。完成本教程:https://spin.atomicobject.com/2014/10/25/ios-unwind-segues/

关于ios - 在具有委托(delegate)的多个 UIViewController 队列上使用解雇 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35749424/

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