In didReceiveRemoteNotification I have
let storyboard = UIStoryboard(name: "RAV", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "AdvanceViewController") as! AdvanceViewController
window?.rootViewController = vc
Inside the app when I navigate to AdvanceViewController the tabBar works, but when I'm open by push, it does not appear.
The Push Works, what does not work it's tabBar
Does anyone know how to do fix it?
The tab bar does not display because you instantiated the view which lies in the tab bar as the root view controller, but that would mean that it is the root controller now, not the tabbar (but you want the tabbar to be the root view controller). What you need to do is set the root view controller to the tab bar and then set the tab bar to the correct index.
Related
So I have an if statement that has 2 outcomes, rootViewController becomes loginViewController or mainSearchViewController. The storyboard for mainSearchViewController has an embedded TabViewController and a NavigationViewController. However, by setting the root view controller, I lose access to both the TabViewController and a NavigationViewControllerand its only the mainSearchViewController that is active. Here is my code:
func setRootViewController() {
if Auth.auth().currentUser != nil {
let mainSearchViewController = storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.mainSearchViewController)
view.window?.rootViewController = mainSearchViewController
view.window?.makeKeyAndVisible()
} else {
let loginSearchViewController = storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.loginViewController)
view.window?.rootViewController = loginSearchViewController
view.window?.makeKeyAndVisible()
Lose access to Tab Bar Controller and Nav Controller when making the root view controller the view on the very right
Edit: I have tried to set the rootViewController to the Tab Controller, this allows me to use the tab functionality but I still don't have access to the Nav Controller. Same goes for the Nav Controller, it works when it is the root view controller but there is no Tab Controller functionality
Edit 2: In the viewDidLoad() of the mainSearchViewControllernavigationController?.isNavigationBarHidden = false` and I have the root view controller as the Tab Bar Controller. I can access the tab icons, and I can see the navigation bar, but the navigation functionality when tapping on a cell doesn't work.
Changing rootViewController is likely causing your problem since tabViewController probably doesn't have loginViewController as a tab.
If you need to display loginViewController based on an if statement, it's better practice to show it using something like:
navViewController.pushViewController(loginViewController, animated: true)
I am working with UISplitViewController. I have UISplitViewController which contain UITabBarController. So I want to display tab bar in all the screen through out the application (Even in detail screen of UISplitViewController for iPhone). Please see the approach:
use segue to move from one controller to another controller or move via navigation so in the next controller your tabbar will be show
just like if u want to move from A to B Controller set stroyboard id ie "SecondVc"
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "SecondVc")
self.navigationController?.pushViewController(vc, animated: true)
or just make connection using storyboard
I'm trying to trigger a modal view from the AppDelegate every time the app is opened. I can see my breakpoint being hit, but the modal never shows. I'm including an image of my storyboard in case it matters. It's a fairly simple app right now with a 2 tab tab bar controller.
This is the code I have in the AppDelegate to trigger it.
let newVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "LoginView")
let view = window?.rootViewController as! UITabBarController
view.selectedViewController?.show(newVC, sender: nil)
It seems newVC is not in the tab bar's controllers array, and you're attempting to modally present it from the selectedViewController in AppDelegate where there probably isn't a selected view controller yet.
One solution is to present newVC after viewDidLoad of the selected view controller (view controller at selectedIndex). If the presentation must take place before any of the tab bar's view controllers are loaded, then you might wanna set it as the window's root view controller and set the root to be the tab bar once newVC has finished its business.
I have navigationController embedded VC(Viewcontroller) in storyboard 1 which is connected to storyboard reference of storyboard 2.
Now, I have VC2 which is again NavController Embedded in storyboard 2.
I am performing the following code :
let storyboard = UIStoryboard(name: "Settings", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "setEdit") as? EditProfile
navigationController?.pushViewController(vc!, animated: true)
settings is storyboard 2, setEdit is ID from navigationController of the destination VC.
When I execute this code, It doesnt perform the presentation of new controller. Also, I have a custom segue class that transitions VCs from Right to Left.
when I use :
present(vc!, animated: true, completion: nil)
It just pushes the VC from bottom to top.
Now I am totally out of Ideas.
My query is:
How can I exactly implement custom segue from one storyboard to another, having navigation bar at the top.
When you use UINavigationController the transition is showed as you said from right to left (push), when you present a view controller modally the presentation style and the transition style are different. Now you cannot connect two navigation controllers, so I suggest to connect directly the controller in the settings storyboard without embedding it in another navigation controller. In settings storyboard you have to set your EditProfileVC as initial view controller and check its identifier and then you can push it from your first storyboard.
I am reseting my root VC in my app using:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let vc = storyboard.instantiateViewControllerWithIdentifier("testVc")
let navigationController = self.view.window?.rootViewController as! UINavigationController
navigationController.setViewControllers([vc], animated: true)
So since I dont have a segue I have a sotyboard id for that VC. The only problem now is that I dont know how to add a navigation bar in my storyboard to that VC.
The VC shows up as completly white/empty in my storyboard but once I run my app and it gets assigned as root it also get a navigation bar which is right, but I would want to add one using storyboard and not code.
If I simply drag a navigation bar in storyboard and start the app. It will result in the navigation bar being placed under the other navigation bar.
You do not add a navigation bar in the storyboard. We're going to use the navigation controller's navigation bar.
You add a navigation item in the storyboard. Now you can configure, in the storyboard, what should be in the navigation bar when you are in a navigation interface.