Go back to view controller from tab bar controller
You can try
self.navigationController?.navigationController?.popToRootViewController(animated: true)
How to dismiss a Tab Bar Controller and go back to previous view controller on click of button
You added tabBarController in secondViewController as subView. So you need to remove that tabBarController view from super view.
For that, you need a tabBarController object.
self.tabBarController?.view.removeFromSuperview()
TabBarController disappears when I segue back to the view from another view
You are following a wrong hierarchy. You are actually using seagues to go back and forth. This creates a new instance every time you try to come back to the first controller.
Let's make it clear:
You need to follow the below approach:
1 You have two controllers A and B.
2 Use self.hidesBottomBarWhenPushed = true in viewDidLoad or viewWillAppear of controller A.
3 Controller A is embedded in a navigation controller which is further embedded in a UITabBarController.
Tapping a button in controller A, you need to push to controller B. So you can use segue for this or you can do it programatically like:
let controllerB = B()
A.navigationController?.pushViewController(controllerB, animated: true)
4 Go Back to Controller A on the tap UIBarButtonItem. So your code in the action of UIBarButtonItem should be something like:
self.navigationController?.popViewController(animated: true)
Remember you should not should segue to go back to the previous controller.
How to dismiss controller and then switch tabs
Make sure you have a UINavigationController
as the first ViewController. Then you have access to the tabBarController and can then switch the tabs:
// if vc was pushed
@IBAction func onFinish(_ sender: Any) {
// store tabBarController for later use
let tabBarController = self.tabBarController
// pop to root vc (green one)
_ = self.navigationController?.popToRootViewController(animated: false)
// switch to 2nd tab (red vc)
tabBarController?.selectedIndex = 1
}
// if vc was presented modally
@IBAction func onFinish(_ sender: Any) {
self.dismiss(animated: false, completion: nil)
if let tabBarController = self.presentingViewController as? UITabBarController {
tabBarController.selectedIndex = 1
}
}
// if vc was presented modally + switching tab in completion block
@IBAction func onFinish(_ sender: Any) {
if let tabBarController = self.presentingViewController as? UITabBarController {
self.dismiss(animated: true) {
tabBarController.selectedIndex = 1
}
}
}
My tab bar and navigation controller disappears when i register for account
I should see the full Storyboard logic to give you a better answer, but I think your answer will be somewhere the presentation style.
NOTE: Only a suggestion, but your view hierarchy should be reviewed, because when you log in your homeviewcontoller(you can "pop" back, or you can replace the whole viewstack) should be your rootviewcontroller, and if I understand correctly there is a stack when you click through login. But here is a possible quick fix:
homeVC.modalPresentationStyle = .currentContext
If it does not help, one of these will:
https://developer.apple.com/documentation/uikit/uimodalpresentationstyle
Changing view controller to tab bar controller
First of all, presentViewController:animated:completion:
will present SettingsViewController
modally. What you need is a UINavigationController flow.
1) Add create UITabBarController
2) Select the item(UIViewController) that will has a UINavigationControler
flow.
3) Delete it
4) Add UITableViewController
5) Add the new UITableViewController
to the UITabBarController
6) Select the UITableViewController
and embed in(Editor > Embed In > Navigation Controller) to a Navigation Controller.
7) Add a UIViewController
and add a segue(Show) between UITableViewController
and UIViewController
8) The result final result should be something like this:
Related Topics
iOS Coredata Compatible with Both iOS 9 and iOS 10
How to Insert UIlabel After UItextfield in UIalertcontroller
Add Assets to an Icloud Shared Photo Album Programmatically
Sklabelnode Text with Two Different Fonts and Colour. How Is This Possible
Sandbox Entitlement to Script Itunes via Nsapplescript
How to Pass Data Backwards to a View Controller After Passing Forward
Why My Arguments Are Being Blocked When Running a Shell Command
Swift: Gradient Splits on Rotation
How to Get The Range of The First Line in a String
How to Load Lcr Image in Tvos Apps
How to Hide The Top Bar (With Buttons) Usin Swift and Macos
How to Post Parameter with (+ Plus Sign) in Alamofire
Implement a Custom Staggeregrid in UIview Like Etsy App in Swift
Wrong Value Returned After Formatting Timestamp
Post Urlrequest Doesn't Work in Swift 4
Nstimer() - Timer.Invalidate Not Working on a Simple Stopwatch