Tab bar and Navigation bar disappeared when navigate from Appdelegate - swift

I use Storyboard. When I tried to navigate to another View from AppDelegate, the Tab bar and Navigation bar in that View were disappeared
Here is the code
//Some conditions here
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeView = storyBoard.instantiateViewController(withIdentifier: "HomeViewController")
self.window?.rootViewController?.present(homeView, animated: true, completion: nil)

Select ViewController from the storyboard.
Go to the Editor and Embed with Navigation Controller or Tab Bar Controller
Give Storyboard ID to your Navigation Controller or Tab Bar Controller
Assign that Navigation Controller or Tab Bar Controller to Root Viewcontroller from AppDelegate.
let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let Root_Vc = storyBoard.instantiateViewController(withIdentifier: "RootVc")
self.window?.rootViewController?.present(Root_Vc, animated: true, completion: nil)

You are just loading the viewcontroller on to the rootview. That's why you can't see tabbar or Navigation bar. You need to present Tabbar or navigation controller in order to see it.

let storyBoard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeView = storyBoard.instantiateViewController(withIdentifier: "HomeViewController")
self.window?.rootViewController = UINavigationController(rootViewController: homeView)
use this code it should work for you

Related

Navigation Bar is shown only at the first tabBarController

I've got a tabBar with 3 screens (Home, Favorite and Settings). Use Storyboard. All these screens have a NavigationController. Navigation Bar is shown only at the first screen - Home, other have no Navigation Bar (no title, no button). Why is this happening?
Upd: I have this problem only on Simulator but on real iPhone everything is good.
My AppDelegate:
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.makeKeyAndVisible()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController")
self.window?.rootViewController = initialViewController
Also I have Login page before TabBarController, going to TabBarController from Login by this method:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let singInViewController = storyboard.instantiateViewController(withIdentifier: "TabBarController")
UIApplication.shared.keyWindow?.rootViewController = singInViewController
self?.present(singInViewController, animated: true, completion: nil)
Add Each View Controller Separate Navigation Bar and attach UINavigation Controller to Tab Bar Controller.

How to find out a tab bar controller inside a SlideMenuController swift?

I have implemented an EXSlideMenuController and added a TabBarController as a main view controller in the sliding menu controller but now I want to find out the first view controller of TabBarController which is inside the EXSlideMenuController.
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let menuViewController = storyboard.instantiateViewController(withIdentifier: "menuViewController") as! MenuViewController
let initialViewController = storyboard.instantiateViewController(withIdentifier: "TabBarControllerID") as! TabBarController
let revealController = ExSlideMenuController(mainViewController: initialViewController, leftMenuViewController: menuViewController)
self.window?.rootViewController = revealController
self.window?.makeKeyAndVisible()
how do I find out the first view controller of tab bar controller from the ExSlideMenuController?
Here is the solution to find out the first view controller of a tab bar controller inside an ExSlideMenuController
let rootController = self.window?.rootViewController as! ExSlideMenuController
let customTabBarController = rootController.mainViewController as! CustomTabBarController
let navBarController = customTabBarController.viewControllers?.first as! UINavigationController
let storeController = navBarController.viewControllers.first as! StoreListViewController
may be it will help some other person.

Present ViewController from UNUserNotificationCenterDelegate

In my UNUserNotificationCenterDelegate method I want to jump the user to a specific view controller. I can easily get the VC itself from the storyboard:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "beach")
What I'm not entirely sure of though is now how to actually present it, since I don't have an object handy to call presentViewController on.
If your root is navigationVC
if let nav = self.window?.rootViewController as? UINavigationController {
nav.pushViewController(vc, animated: true)
}

Navigation through TabbarController And NavigationController. How?

i have storyboard file like this:enter image description here
when user is loggedin i make segue with:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialVC: UITabBarController = storyboard.instantiateViewController(withIdentifier: "loggedin") as! UITabBarController
self.present(initialVC, animated: true, completion: nil)
and automaticly open viewcontroller with identifier "selectsaloon", but sometimes depending on the condition I need to go to viewcontroller with identifier "searchparams". help me find a solution
You can Make navigation on viewdidload for selectsaloon when condition occuer
if (condition) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialVC: UIVieWController = storyboard.instantiateViewController(withIdentifier: "searchparams") as! UIViewController
self.navigationController.push(initialVC, animated: true)
}

How to correctly display a tab controller in swift

I'm making a login screen for my app and everything works as intented until I try to present my main view after the login(which uses a Tab Bar Controller).
The only problem is that it displays just the first item on the tab bar. I have to press the other buttons for the to appear.
Im using this code:
//after login...
var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var vc: TabBarViewController = storyboard.instantiateViewControllerWithIdentifier("MainController") as! TabBarViewController
self.presentViewController(vc, animated: true, completion: nil)
My guess is that I need to load them all at the same time, but I dont know...
This is how I did it recently. I loaded my tabBarController and the login screen together, once the user has logged in (or completed the first screen experience) you can modally dismiss the controller.
func showloginView() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let loginViewController: LoginTableViewController = storyboard.instantiateViewControllerWithIdentifier("LoginTVC") as! LoginTableViewController
self.window?.makeKeyAndVisible()
var viewController = storyboard.instantiateViewControllerWithIdentifier("LoginTVC") as! LoginTableViewController
let nav = UINavigationController(rootViewController: viewController)
self.window?.rootViewController?.presentViewController(nav, animated: true, completion: nil)
}
for displaying your tabBarController and editing of any of the tabBarItems
let tabBarController = self.window?.rootViewController as? UITabBarController
let tabBarRootViewControllers: Array = tabBarController!.viewControllers!
let nav = tabBarRootViewControllers[0] as? UINavigationController
Hope this helps =)
If you link an UIButton, you can open a UITabBarController using this (providing you're using a Storyboard)
#IBAction func openTabBar(sender: AnyObject) {
var tabBarController = self.storyboard?.instantiateViewControllerWithIdentifier("tabBarController") as! UITabBarController
self.presentViewController(tabBarController, animated: false, completion: nil)
}
That'll pop the current view and open the tab bar controller.