[英]How to segue to view controller from TabbarController?
我有一个TabbarController
,它是我应用程序的入口点,所以我想将此TabbarController
到ViewControllerA
。 我执行performSegue(with: "identifier")
。我可以到达ViewControllerA
,但是当我到达ViewControllerA
,没有NavigationBar
我试图将ViewControllerA
嵌入到NavigationController
1st中,所以故事板看起来像这样
TabbarController-> NavigationController-> ViewControllerA
这样,我可以到达ViewControllerA。但是我在prepareForSegue方法中遇到了问题。因为我需要在segue中包含一个值,现在似乎不包含该值。
我在prepareForSegue中的代码如下所示:
if let VcA = segue.destination.navigationController?.topViewController as? ViewControllerA {
VcA.postId = sender as! Int
}else{
print("cant work")
}
我也尝试将tabbarController嵌入到NavigationController中,但是在Xcode-> Editor -> Embed
该选项被禁用。
所以我的问题是
如何从TabbarController切换到ViewController,并且在目标位置的NavigationBar是可见的,并且可以返回到上一屏幕?
假设您的情节提要类似于:
那是因为您在TabbarController
中调用了performSegue(with: "identifier")
,而TabbarController
没有直接连接到segue。 您应该怎么做才能在连接到导航控制器( ViewControllerA
)的第一个视图控制器中实现它。 因此,例如:
class ViewControllerA: UIViewController {
// ...
override func viewDidLoad() {
super.viewDidLoad()
performSegue(with: "identifier")
}
// ...
}
因此,您的选择应该是从ViewControllerA
到所需的视图控制器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.