How to hide Tabbarcontroller's first view controller and go directly to the next controller but should show the tab bar items at the bottom

Multi tool use
Multi tool use


How to hide Tabbarcontroller's first view controller and go directly to the next controller but should show the tab bar items at the bottom



I have a view controller as my initial view controller. there's a button in it(GO button) which when the user taps, it should go to another view controller(let's call it Destination view controller with label 'This is where i wanna go'). Meanwhile i want to pass it through a Tabbar controller. The reason is i want to have tabbar in my navigation stack.
I wish to go directly to the Destination view controller while pressing go button but it should show the tab bar items at the bottom.
So for achieving this in FirstViewController didLoadMethod I checked a bool value and pushed the view controller to the Destination view controller. I achieved the result I.e when pressing the Go button it goes to the Destination view controller and has tab bar items at it's bottom.
But the problem since it passes through the Tabbarcontroller the FirstViewController is shown for some seconds and then it pushes to the Destination view controller. I wish to hide FirstViewController while this transition takes place.
How to achieve this?
Picture shows what i want. what can I do to hide firstviewcontroller while having it in navigation stack?enter image description here




3 Answers
3



I think this can be done in a simple way -



Put your push navigation code in one of those functions



*You cant see the current view coltroller, it will push the screen to your required viewcontroller before loading the tab bar initial view contoller.



Hope it will work for you.



or >>>> you can check it out


let storyboard = UIStoryboard(name: "your_storyBoard_name", bundle: nil)
let viewController1 = storyboard.instantiateViewController(withIdentifier: "firstViewController")
let viewController2 = storyboard.instantiateViewController(withIdentifier: "secondViewcontroller")
let controllers = [viewController1, viewController2]
self.navigationController!.setViewControllers(self.navigationController!.viewControllers + controllers, animated: true)





Surely i will check to it buddy... If works points to you
– Chelsea Shawra
Jun 29 at 9:07





Did the code work ?
– Rahul Singha Roy
Jul 2 at 6:52





No bro it didnt worked
– Chelsea Shawra
Jul 2 at 8:29





The problem you are facing and the code is not working is - you have a single navigation controller in your project
– Rahul Singha Roy
Jul 2 at 9:54





you can try my edited ans..
– Rahul Singha Roy
Jul 2 at 9:58



The effect you're trying to produce is hard to do in a storyboard. Programmatically you would simply create the Tabbar Controller (with its children) and the "This is where I want to go" Controller, and then ask the navigation controller to show both at the same time.



For example, after "Go" is tapped, this is the code I would run inside your first view controller:


let tabBarController = UITabBarController()
let finalDestination = UIViewController()

var viewControllers = self.navigationController?.viewControllers ??
viewControllers.append(tabBarController)
viewControllers.append(finalDestination)

self.navigationController?.setViewControllers(viewControllers, animated: true)





i will surely check with this code and if it works.
– Chelsea Shawra
Jun 29 at 5:56





Its still having the same effect
– Chelsea Shawra
Jul 3 at 10:57



Given the structure you shown, where the view controller A is the root view controller of the TabBar, you should push the second view controller B on the navigation stack inside either willAppear or didLoad of view controller A, according to your personal business logic (flag, conditions, etc.).



The trick here is to use either pushViewController or setViewControllers with animated: false so that the navigation stack will be set immediately during willAppear/didLoad and it won't show the push animation of B over A. This way, at onDidAppear the layout will be already fully rendered in it's final state: with B at the top of the navigation stack and no animations in progress.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

g,iYM6s,kQ SXDr98jU
1 W7iP1YDVKwgaQSokfiTzRLpsIAmld4GCtfdb,92Q0Y

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications