when user click a button at some cell (view) i want to push to another tab's viewcontroller
tabbarController
--- nav controller ---- VC A
--- nav controller ---- VC B
--- nav controller ---- VC C ---- VC D
like from viewcontroller A to viewcontroller D
i tried segue
self.window?.visibleViewController?.performSegue(withIdentifier:"homeSegueDetailStatement", sender: self)
worked but without nav bar....
i tried create a nav controller and present , crashed...
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)
}
please help me
EDIT---
actually i want to change tab and nav to second view controller. and i call this func from collectionCell ,that's why i have to ge current viewcontroller
EDIT--- i found what i want
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)
}
}
}
}