问题
How can I segue to a tab bar controller? Theres 2 view controllers on tabs with navigation controllers and a navigation controller on the tab bar controller.
let storyboard = UIStoryboard(name: "PendingOverview", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "PendingOverviewVC") as! PendingOverViewController
let nc = UINavigationController(rootViewController: vc)
self.present(nc, animated: false, completion: nil)
Thank you
回答1:
In Storyboard
set identifier to UITabbarController
and then using instantiateViewController
present that UITabbarController
.
let storyboard = UIStoryboard(name: "PendingOverview", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabbarIdentifier") as! UITabbarController
if let vcs = tabbarVC.viewControllers,
let nc = vcs.first as? UINavigationController,
let pendingOverVC = nc.topViewController as? PendingOverViewController {
pendingOverVC.pendingResult = pendingResult
}
self.present(tabbarVC, animated: false, completion: nil)
来源:https://stackoverflow.com/questions/42593088/instantiate-view-controller-swift-3-tab-bar-controller