gpt4 book ai didi

ios - 执行 segue 以查看选项卡和导航 Controller 后面的 Controller

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

我在访问位于 TAB 和 NAV Controller 后面的 View Controller 时遇到问题。

我可以访问第一个 VC(见下面的代码)但我无法访问第四个 VC。

         SenderVC----->TabBarVC-⎜----NavVC----FirstVC
⎜----NavVC----SecondVC
⎜----NavVC----ThirdVC
⎜----NavVC----FourthVC

我做错了什么?

如果有人能为我指出正确的方向,那就太好了。谢谢。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

if (segue.identifier == "segueVC0") {
let tabVC = segue.destination as! UITabBarController
let navVC = tabVC.viewControllers![0] as! UINavigationController
let destVC = navVC.viewControllers[0] as! FirstVC // ==> this transition is working

} else if (segue.identifier == "segueVC4") {
let tabVC = segue.destination as! UITabBarController
let navVC = tabVC.viewControllers![4] as! UINavigationController
let destVC = navVC.viewControllers[0] as! FourthVC // ==> this transition is NOT working !!!

} else {
print ("wrong segue ID")
}
}

最佳答案

你好,我得到了第四个 VC 的实例

类 View Controller :UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

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

@IBAction func buttonTapped(sender: AnyObject) {
print("ViewController - buttonTapped()")
performSegue(withIdentifier: "seg4", sender: self)
}


override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "seg1" {
let tabVC = segue.destination as! UITabBarController
let navVC = tabVC.viewControllers![0] as! UINavigationController
let destVC = navVC.viewControllers[0] as! Seq1 // ==> this transition is working

print(destVC)

}
else if segue.identifier == "seg4"{
let tabVC = segue.destination as! UITabBarController
let navVC = tabVC.viewControllers![3] as! UINavigationController
let destVC = navVC.viewControllers[0] as! Seq4 // ==> this transition is working
destVC.hello()
print(destVC)
}

}

Seq1 类:UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

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

Seq2 类:UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

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

}Seq3 类:UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.


}



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

}Seq4 类:UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
print("Hello")
// Do any additional setup after loading the view, typically from a nib.
}

func hello() {
print("Hello")
}

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

注意:标签栏 Controller 将始终显示 FirstVC。因为它是默认选择。如果需要,更改 selectedIndex = 3

关于ios - 执行 segue 以查看选项卡和导航 Controller 后面的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42702434/

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