我想切换标签栏项目 2,但它总是转到项目 1。在日志中,它说它也转到项目 2,但它显示项目 1。我正在使用 segue。视图控制器![1]
if segue.identifier == Constants.Identifiers.goToWinTabFromSearchMatch {
let tabBarController = segue.destination as! UITabBarController
let navController = tabBarController.viewControllers![1] as! UINavigationController
let controller = navController.topViewController as! WinViewController
}
@IBAction func doneToBackToWinTab(_ sender: Any) {
print("i wana back to the win tab")
performSegue(withIdentifier: Constants.Identifiers.goToWinTabFromSearchMatch, sender: nil)
}
我也对你的代码片段感到困惑,因为它只是声明了一堆常量,你在这里没有执行任何操作。要更改 中的选项卡UITabViewController
,只需使用selectedIndex
属性(这是一个简单的Int
)。将其设置为有效值,瞧。
但是,您的if
块中有许多关于选项的问题。强制解包和访问甚至可能不存在的数组字段只是自找麻烦。我强烈建议您以正确的方式进行操作并通过if let
.
即,您tabBarController.viewControllers![1] as! UINavigationController
实际上就像将一罐煤油放在明火旁边 - 您不知道何时但它最终会爆炸。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句