I have a container View where the upper half shows some details and th lower half shows the navigation to a particular place.
A is my View Controller with a container View , Now i have B View Controller which occupies bottom Half of the A View Controller. I have another View Controller C which is being presented from B, but instead of occupying the bottom half , it occupies entire screen. How can i fix it so that whatever happens after interaction fro View Controller B it stays in the bottom half of the screen ?
In the bottom half the view controller first takes in a few values and them presents a view Controller.
Now when i present a new View Controller it occupies entire screen
Directions.shared.calculate(options) { (waypoints, routes, error) in
guard let route = routes?.first else { return }
let viewController = NavigationViewController(for: route)
self.present(viewController, animated: true, completion: nil)
}
Finally i found out a way. Just writing up incase any one would require.
I just embedded my View Controller B into a Navigation Controller and
let viewController = NavigationViewController(for: route)
self.navigationController?.pushViewController(viewController, animated: true)
Related
In my project you can create a post from a modal view.
When the modal view is dismissed (user presses on save post) I want to switch the tab bar controller to the second tab (post feed screen).
This topic is similar to my problem. The only difference being this is presented from a modal view. I can't figure out how to implement it in my code (tab bar is nil)
Switch tab bar programmatically in Swift
I have added 3 images to make this issue clearer
code screenshot
console message
#objc func saveAction(sender: UIButton) {
print ("> save pressed")
print(presentingViewController?.tabBarController)
print(presentingViewController)
presentingViewController?.tabBarController?.selectedIndex = 1
dismiss(animated: true)
}
edit: sorry stack overflow doesn't allow me to add images yet
You can do this using delegate pattern. But if you prefer not to add a delegate for this, you can do as shown below;
You can switch the tabbar by changing the selectedIndex property of tabBarController
if let presenter = presentingViewController as? LibraryViewController {
presenter.tabBarController?.selectedIndex = 1
}
dismiss(animated: true)
If you are presenting the modal on navigation controller in tabbar, use:
if let tabBar = presentingViewController as? UITabBarController {
tabBar.selectedIndex = 1
}
dismiss(animated: true)
My tab bar controller is not embedded in a navigation controller.
On index 1 (which is embedded in a navigation controller) I have an alert that should show a view controller inside index 2 (also embedded in its own navigation controller).
I would like to jump to the view controller which is inside index 2 (called subVC). The following code does not work. navController is coming up nil.
let subVC = self.storyboard?.instantiateViewController(withIdentifier: Constants.Storyboard.subscriptionVC) as! SubscriptionViewController
self.selectedIndex = 2
let navController = self.tabBarController?.selectedViewController?.navigationController
navController?.pushViewController(subVC, animated: true)
I created a tab bar controller and from one tab item I gave segue to the navigation view controller. And I create a some view controllers attached to navigation controller. So in one view controller I don't need a tabs so in that controller I wrote to hide the tab bar controller that is self.tabBarController?.tabBar.isHidden = true.
When I click the back button of navigation controller from hided tab view controller to previous controller, it doesn't show the tab bar items in previous controllers. But I needed tabs in all view controller except in one view controller. Why does it not show the tabs?
This is my story board :
You can try this in the VC that's before the one you hide the tab in
override func viewWillAppear(_ animated:Bool) {
super.viewWillAppear(animated)
self.tabBarController?.tabBar.isHidden = false
}
You can use hidesBottomBarWhenPushedin the view controller which you don't need tabs. Fits your situation.
let controller = ViewControllerTwo()
controller.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(controller, animated: true)
A little more explanation:
self.tabBarController?.tabBar.isHidden = true globally changed the self.tabBarController's property hideTabBar across its children controllers stack.
I have an app that uses a UITabBarController and has 4 children (navigation controllers).
iPad:
I am in the first tab (navigation controller) and I push a UIViewController from a cell. The view (x) that is now showing is under the top and bottom bars.
I then navigate to the second tab (navigation controller) and then again back to my first tab.
Now the view (same X) is displayed ok and not under the bars anymore.
If I test this on an iPhone the view is always rendered as it should (and not under the bars). All the navigation controller and all the viewControllers have underTopBars / underBottomBars and adjustScrollViewInsets deselected.
let releaseViewController = storyboard.instantiateViewController(withIdentifier: "qwerty") as? VCClass
releaseViewController?.navigationItem.title = datasource.asd?.name
releaseViewController?.datasource = datasource.asd
self.navigationController?.pushViewController(releaseViewController!, animated: true)
Try to check these box in your storyboard for both controllers.
Let me know if it has worked.
In my application, I have a default tab selected for my Tab Bar Controller. On the viewDidLoad() of the default tab, I have this:
if (NSUserDefaults.standardUserDefaults().stringForKey("defaultCode") == nil) {
//let navController:UINavigationController = UINavigationController()
//self.presentViewController(navController, animated: true, completion: nil)
self.tabBarController!.selectedIndex = 1
I thought calling selectedIndex would do what I was looking forever; however, it only changes the selected tab in the TabBar, but my view does not change. The area I commented out quickly shows the proper view, then goes to a black screen. The view I am trying to switch to is a Navigation Controller
selectedIndex always be the first and pop/push after selected