Push navigation iPad issue - iphone

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.

Related

Push View Controller from Tab Bar Controller

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)

How to display the tabs when click the back button from hided tab view controller

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.

How to present a view Controller from a container View?

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)

Segue To Navigation Controller in Tab Bar Controller

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

navigationController is nil in swift

I have two storyboard (Main and SB2)
I have one view controller in storyboard in Main and one in SB2
I perform
let SB2 = UIStoryboard(name: "SB2", bundle:nil)
let vc : UIViewController = self.SB2.instantiateViewControllerWithIdentifier("VC2")
self.showViewController(vc, sender: self)
After the second viewcontroller loads and this command is run, it prints nil:
print(self.navigationController) // prints nil
In SB2 (second storyboard) I clicked on the viewcontroller (VC2) and then clicked on Editor > Embed In > Navigation Controller. This placed a navigation controller with the storyboard and the root view controller is VC2. I triple checked this. The first sign of it being connected was the gray navigation bar on top. The second being that there is segue connecting the navigation controller to VC2 and the last place I could have checked is in the navigation controller utilities.
I am thinking that maybe I shouldn't transition from VC1 to VC2 directly but rather VC1 to NavigationController however I don't know how to do this or if its even possible.
I don't know when sb2 prints nil when in face a navigation controller is connected to it. Any help is appreciated.
You need to push the view controller (VC2) on to the navigation controller.
let SB2 = UIStoryboard(name: "SB2", bundle:nil)v
let nvc = SB2.instantiateViewControllerWithIdentifier("NVC") as! UINavigationController
let vc : UIViewController = self.SB2.instantiateViewControllerWithIdentifier("VC2")
nvc.pushViewController(vc, animated: true)
Then in your view controller try calling
self.navigationController
In your storyboard,
select the initial ViewController. With this view controller selected, choose the menu item
Editor -> Embed In -> Navigation Controller