当用户点击某个单元格中的按钮时(查看) 我想推送到另一个标签的viewcontroller
tabbarController
---导航控制器---- VC A
---导航控制器---- VC B
---导航控制器---- VC C ---- VC D
从viewcontroller A到viewcontroller D
我试过了segue
self.window?.visibleViewController?.performSegue(withIdentifier:"homeSegueDetailStatement", sender: self)
工作但没有导航栏......
我尝试创建一个导航控制器并呈现,崩溃......
if let visibleViewCtrl = UIApplication.shared.keyWindow?.visibleViewController {
let nav = UINavigationController(rootViewController: visibleViewCtrl)
let b = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PendingStatementVC") as! PendingStatementViewController
nav.pushViewController(b, animated:false)
visibleViewCtrl.present(nav, animated:true, completion:nil)
}
请帮帮我
EDIT ---
实际上我想将标签和导航更改为第二个视图控制器。 我从collectionCell调用这个函数,这就是为什么我必须使用当前的viewcontroller
EDIT --- 我找到了我想要的东西
DispatchQueue.global().async {
DispatchQueue.main.async {
self.tabBarController?.selectedIndex = 2
if let controller = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "DetailStatementVC") as? DetailStatementViewController {
if let navigator = self.tabBarController?.viewControllers?[2] as? UINavigationController {
navigator.pushViewController(controller, animated: true)
}
}
}
}
答案 0 :(得分:4)
使用下面的代码,您可以从VC-A转到VC-D,然后可以从VC-D返回到VC-C
let dViewController = self.storyboard?.instantiateViewController(withIdentifier: "DViewController") as! DViewController
let thirdTabNavController = self.tabBarController?.viewControllers?[2] as! UINavigationController
thirdTabNavController.pushViewController(dViewController, animated: false)
self.tabBarController?.selectedIndex = 2
答案 1 :(得分:0)
尝试这样的事情:
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "mainView") as! MainViewController
self.present(nextViewController, animated:true, completion:nil)
答案 2 :(得分:0)
试试这个
let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let MainViewControllerObj : MainViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "MainViewController") as! MainViewController
let navigationControllerObj:UINavigationController = UINavigationController.init(rootViewController: MainViewControllerObj)
self.present(navigationControllerObj, animated:true, completion:nil)
答案 3 :(得分:0)
Kamil3的答案肯定是最好的,但是如果有人需要在导航栏中的“后退”按钮旁边隐藏标题,我发现解决方案不是很优雅,但是想分享,因为它花了我很多时间:
guard let dViewController =
self.storyboard?.instantiateViewController(withIdentifier: "DViewController") as! DViewController,
let thirdTabNavController = self.tabBarController?.viewControllers?[2] as! UINavigationController else {
return
}
self.tabBarController?.selectedIndex = 2
// here what you need
thirdTabNavController.viewControllers.first?.title = " "
thirdTabNavController.pushViewController(dViewController, animated: false)
答案 4 :(得分:-1)
Try below code:
let mainStoryBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = mainStoryBoard.instantiateViewController(withIdentifier: "DcontrollerIdentifier") as! DViewController
self.navigationController?.pushViewController(nextViewController, animated: true)