I want to change my entry Point of my project but how I can do that? I don't use the storyboard, I do it all programmatically and I want my secondViewController to be the firstViewController.
Thanks in advance!
without storyboard start with your specific ViewController put this code in didfinishlaunchingwithOptions method in AppDelegate.
let homeVC = SecondViewController()
self.window?.rootViewController = homeVC
self.window?.makeKeyAndVisible()
with storyboard
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let homeVC = storyboard.instantiateInitialViewController()
self.window?.rootViewController = homeVC
self.window?.makeKeyAndVisible()
Related
I have two view controller in the TabBar. I set up like if user is logged in then it's directly show the TabBar else it's showing loginViewController. Look the Code in AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true])
let status = UserDefaults.standard.bool(forKey: "status")
//StoryBoard Decide
if (status == false){
let storyBoard : UIStoryboard = UIStoryboard(name: "Tools", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
let navigationController = UINavigationController(rootViewController: nextViewController)
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.window!.rootViewController = navigationController
}else {
let storyBoard : UIStoryboard = UIStoryboard(name: "Tools", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "tabbar") as! UITabBarController
let navigationController = UINavigationController(rootViewController: nextViewController)
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.window!.rootViewController = navigationController
}}
But when it's work proper when i go through login ViewController but when user is alredy logged in it's showing the navigation bar in the HomeViewController.
This is my storyBoard Setup.
And also how to manage the Navigation with TabBar.
Because you are making new navigation controller then add tabbar as its root view.
Instead of making UINavigationController you can do this:
Replace
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "tabbar") as! UITabBarController
let navigationController = UINavigationController(rootViewController: nextViewController)
let appdelegate = UIApplication.shared.delegate as! AppDelegate
appdelegate.window!.rootViewController = navigationController
with:
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "tabbar") as! UITabBarController
self.window?.rootViewController = nextViewController
self.window?.makeKeyAndVisible()
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.
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)
}
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)
}
I'm using push notifications on my app. So, when I receive a notification and touch it, I want go to another UITabbarcontroller, but when I doing it the app only show the UINavigationbar and don't the UITabbarcontroller. This a screenshot -->
And this my code.
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "RequestDriverViewController") as! RequestDriverViewController
let nc = UINavigationController(rootViewController: vc)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = nc
self.window?.makeKeyAndVisible()
I was able to solve it:
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "TabBarIdentifier") as! UITabBarController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = vc
self.window?.makeKeyAndVisible()