How to reset tab (or tab controller) of UITabBarController when user select tab?
up vote
1
down vote
favorite
Swift: I have UITabBarController, with 8 tabs. When user select any tab including more tab, I want reset content of selected tab by Popping to rootView controller?
How could this be done?
I tried to reset navigation controllers in below methods, It works for tabs which are visible at bottom but it doesn't work for More
tab.
tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
ios swift xcode uitabbarcontroller uitabbar
add a comment |
up vote
1
down vote
favorite
Swift: I have UITabBarController, with 8 tabs. When user select any tab including more tab, I want reset content of selected tab by Popping to rootView controller?
How could this be done?
I tried to reset navigation controllers in below methods, It works for tabs which are visible at bottom but it doesn't work for More
tab.
tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
ios swift xcode uitabbarcontroller uitabbar
what have you tried already? show some code, show what errors your getting or explain it in more detail
– Scriptable
Apr 28 '17 at 10:37
@Scriptable I tried to reset navigation controllers in method tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
– Gaurav Borole
Apr 28 '17 at 10:41
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Swift: I have UITabBarController, with 8 tabs. When user select any tab including more tab, I want reset content of selected tab by Popping to rootView controller?
How could this be done?
I tried to reset navigation controllers in below methods, It works for tabs which are visible at bottom but it doesn't work for More
tab.
tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
ios swift xcode uitabbarcontroller uitabbar
Swift: I have UITabBarController, with 8 tabs. When user select any tab including more tab, I want reset content of selected tab by Popping to rootView controller?
How could this be done?
I tried to reset navigation controllers in below methods, It works for tabs which are visible at bottom but it doesn't work for More
tab.
tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
ios swift xcode uitabbarcontroller uitabbar
ios swift xcode uitabbarcontroller uitabbar
edited Mar 1 at 9:51
Krunal
35.6k20130156
35.6k20130156
asked Apr 28 '17 at 10:32
Gaurav Borole
3721624
3721624
what have you tried already? show some code, show what errors your getting or explain it in more detail
– Scriptable
Apr 28 '17 at 10:37
@Scriptable I tried to reset navigation controllers in method tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
– Gaurav Borole
Apr 28 '17 at 10:41
add a comment |
what have you tried already? show some code, show what errors your getting or explain it in more detail
– Scriptable
Apr 28 '17 at 10:37
@Scriptable I tried to reset navigation controllers in method tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
– Gaurav Borole
Apr 28 '17 at 10:41
what have you tried already? show some code, show what errors your getting or explain it in more detail
– Scriptable
Apr 28 '17 at 10:37
what have you tried already? show some code, show what errors your getting or explain it in more detail
– Scriptable
Apr 28 '17 at 10:37
@Scriptable I tried to reset navigation controllers in method tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
– Gaurav Borole
Apr 28 '17 at 10:41
@Scriptable I tried to reset navigation controllers in method tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
– Gaurav Borole
Apr 28 '17 at 10:41
add a comment |
4 Answers
4
active
oldest
votes
up vote
3
down vote
accepted
A clean way to do this:
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let index = tabBarController.selectedIndex
if index == NSNotFound || index > 4 {
tabBarController.moreNavigationController.popToRootViewController(animated: false)
return
}
let navController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController
navController?.popToRootViewController(animated: false)
}
Create a custom class for your UITabViewContoller, set a delegate and put there that piece of code.
kamil3 It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:58
@GauravBorole Generally Apple dissuades using more than 5 tabs in tab bar: developer.apple.com/ios/human-interface-guidelines/ui-bars/…. Of course that doesn't change the fact that you're right.
– kamil3
Apr 28 '17 at 11:05
kamil3 Yes Thats true, But thats the situation :)
– Gaurav Borole
Apr 28 '17 at 11:06
@GauravBorole I edited my answer - it turns out UITabBarController has moreNavigationController property. Does it meet your requirements?
– kamil3
Apr 28 '17 at 11:40
kamil3 Thanks It works for more tab as well. But I think for MoreTab we need to add check if it is MoreTab index then Pop to root view.
– Gaurav Borole
Apr 28 '17 at 11:43
|
show 2 more comments
up vote
0
down vote
You can create a UITabBarController class for your tabBar and in that class ovveride the tabBar didSelect method from their on select of any tab you can popViewController
class TabBarViewController: UITabBarController {
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
let navigationController1 = self.viewControllers![0] as? UINavigationController
navigationController1!.popViewController(animated: false)
let navigationController2 = self.viewControllers![1] as? UINavigationController
navigationController2!.popToRootViewController(animated: false)
let navigationController3 = self.viewControllers![2] as? UINavigationController
navigationController3!.popToRootViewController(animated: false)
let navigationController4 = self.viewControllers![3] as? UINavigationController
navigationController4!.popToRootViewController(animated: false)
}
}
It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:59
add a screenshot of your storyboard in the question
– harshal jadhav
Apr 28 '17 at 11:00
ViewControllers are programmatically added to UITabBarController. But I guess it doesn't matter wether you are using Storyboard and Programatic way.
– Gaurav Borole
Apr 28 '17 at 11:05
add a comment |
up vote
0
down vote
Use viewControllers
property of UITabbarController
. viewControlers is an array of UIViewController for UITabbarController. Exchange/Move position of view controllers upon tabbar(controller) selection.
Use tabbar(controller)'s delegate method to hanlde these operations, like:
Swift 3
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if var viewcontrollers = tabBarController.viewControllers {
viewcontrollers.remove(at: tabBarController.selectedIndex)
viewcontrollers.insert(viewController, at: 0)
tabBarController.viewControllers = viewControllers
}
}
You can also use this delegate method, if you have an access to tabbarController where you have implemented.
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
// Write a similar code to exchange/move view controllers using tabbarController instance.
}
add a comment |
up vote
0
down vote
This worked for me.
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
guard let navigationController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController else {
return
}
navigationController.popToRootViewController(animated: false)
}
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
A clean way to do this:
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let index = tabBarController.selectedIndex
if index == NSNotFound || index > 4 {
tabBarController.moreNavigationController.popToRootViewController(animated: false)
return
}
let navController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController
navController?.popToRootViewController(animated: false)
}
Create a custom class for your UITabViewContoller, set a delegate and put there that piece of code.
kamil3 It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:58
@GauravBorole Generally Apple dissuades using more than 5 tabs in tab bar: developer.apple.com/ios/human-interface-guidelines/ui-bars/…. Of course that doesn't change the fact that you're right.
– kamil3
Apr 28 '17 at 11:05
kamil3 Yes Thats true, But thats the situation :)
– Gaurav Borole
Apr 28 '17 at 11:06
@GauravBorole I edited my answer - it turns out UITabBarController has moreNavigationController property. Does it meet your requirements?
– kamil3
Apr 28 '17 at 11:40
kamil3 Thanks It works for more tab as well. But I think for MoreTab we need to add check if it is MoreTab index then Pop to root view.
– Gaurav Borole
Apr 28 '17 at 11:43
|
show 2 more comments
up vote
3
down vote
accepted
A clean way to do this:
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let index = tabBarController.selectedIndex
if index == NSNotFound || index > 4 {
tabBarController.moreNavigationController.popToRootViewController(animated: false)
return
}
let navController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController
navController?.popToRootViewController(animated: false)
}
Create a custom class for your UITabViewContoller, set a delegate and put there that piece of code.
kamil3 It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:58
@GauravBorole Generally Apple dissuades using more than 5 tabs in tab bar: developer.apple.com/ios/human-interface-guidelines/ui-bars/…. Of course that doesn't change the fact that you're right.
– kamil3
Apr 28 '17 at 11:05
kamil3 Yes Thats true, But thats the situation :)
– Gaurav Borole
Apr 28 '17 at 11:06
@GauravBorole I edited my answer - it turns out UITabBarController has moreNavigationController property. Does it meet your requirements?
– kamil3
Apr 28 '17 at 11:40
kamil3 Thanks It works for more tab as well. But I think for MoreTab we need to add check if it is MoreTab index then Pop to root view.
– Gaurav Borole
Apr 28 '17 at 11:43
|
show 2 more comments
up vote
3
down vote
accepted
up vote
3
down vote
accepted
A clean way to do this:
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let index = tabBarController.selectedIndex
if index == NSNotFound || index > 4 {
tabBarController.moreNavigationController.popToRootViewController(animated: false)
return
}
let navController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController
navController?.popToRootViewController(animated: false)
}
Create a custom class for your UITabViewContoller, set a delegate and put there that piece of code.
A clean way to do this:
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
let index = tabBarController.selectedIndex
if index == NSNotFound || index > 4 {
tabBarController.moreNavigationController.popToRootViewController(animated: false)
return
}
let navController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController
navController?.popToRootViewController(animated: false)
}
Create a custom class for your UITabViewContoller, set a delegate and put there that piece of code.
edited Apr 28 '17 at 12:46
answered Apr 28 '17 at 10:51
kamil3
4821713
4821713
kamil3 It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:58
@GauravBorole Generally Apple dissuades using more than 5 tabs in tab bar: developer.apple.com/ios/human-interface-guidelines/ui-bars/…. Of course that doesn't change the fact that you're right.
– kamil3
Apr 28 '17 at 11:05
kamil3 Yes Thats true, But thats the situation :)
– Gaurav Borole
Apr 28 '17 at 11:06
@GauravBorole I edited my answer - it turns out UITabBarController has moreNavigationController property. Does it meet your requirements?
– kamil3
Apr 28 '17 at 11:40
kamil3 Thanks It works for more tab as well. But I think for MoreTab we need to add check if it is MoreTab index then Pop to root view.
– Gaurav Borole
Apr 28 '17 at 11:43
|
show 2 more comments
kamil3 It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:58
@GauravBorole Generally Apple dissuades using more than 5 tabs in tab bar: developer.apple.com/ios/human-interface-guidelines/ui-bars/…. Of course that doesn't change the fact that you're right.
– kamil3
Apr 28 '17 at 11:05
kamil3 Yes Thats true, But thats the situation :)
– Gaurav Borole
Apr 28 '17 at 11:06
@GauravBorole I edited my answer - it turns out UITabBarController has moreNavigationController property. Does it meet your requirements?
– kamil3
Apr 28 '17 at 11:40
kamil3 Thanks It works for more tab as well. But I think for MoreTab we need to add check if it is MoreTab index then Pop to root view.
– Gaurav Borole
Apr 28 '17 at 11:43
kamil3 It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:58
kamil3 It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:58
@GauravBorole Generally Apple dissuades using more than 5 tabs in tab bar: developer.apple.com/ios/human-interface-guidelines/ui-bars/…. Of course that doesn't change the fact that you're right.
– kamil3
Apr 28 '17 at 11:05
@GauravBorole Generally Apple dissuades using more than 5 tabs in tab bar: developer.apple.com/ios/human-interface-guidelines/ui-bars/…. Of course that doesn't change the fact that you're right.
– kamil3
Apr 28 '17 at 11:05
kamil3 Yes Thats true, But thats the situation :)
– Gaurav Borole
Apr 28 '17 at 11:06
kamil3 Yes Thats true, But thats the situation :)
– Gaurav Borole
Apr 28 '17 at 11:06
@GauravBorole I edited my answer - it turns out UITabBarController has moreNavigationController property. Does it meet your requirements?
– kamil3
Apr 28 '17 at 11:40
@GauravBorole I edited my answer - it turns out UITabBarController has moreNavigationController property. Does it meet your requirements?
– kamil3
Apr 28 '17 at 11:40
kamil3 Thanks It works for more tab as well. But I think for MoreTab we need to add check if it is MoreTab index then Pop to root view.
– Gaurav Borole
Apr 28 '17 at 11:43
kamil3 Thanks It works for more tab as well. But I think for MoreTab we need to add check if it is MoreTab index then Pop to root view.
– Gaurav Borole
Apr 28 '17 at 11:43
|
show 2 more comments
up vote
0
down vote
You can create a UITabBarController class for your tabBar and in that class ovveride the tabBar didSelect method from their on select of any tab you can popViewController
class TabBarViewController: UITabBarController {
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
let navigationController1 = self.viewControllers![0] as? UINavigationController
navigationController1!.popViewController(animated: false)
let navigationController2 = self.viewControllers![1] as? UINavigationController
navigationController2!.popToRootViewController(animated: false)
let navigationController3 = self.viewControllers![2] as? UINavigationController
navigationController3!.popToRootViewController(animated: false)
let navigationController4 = self.viewControllers![3] as? UINavigationController
navigationController4!.popToRootViewController(animated: false)
}
}
It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:59
add a screenshot of your storyboard in the question
– harshal jadhav
Apr 28 '17 at 11:00
ViewControllers are programmatically added to UITabBarController. But I guess it doesn't matter wether you are using Storyboard and Programatic way.
– Gaurav Borole
Apr 28 '17 at 11:05
add a comment |
up vote
0
down vote
You can create a UITabBarController class for your tabBar and in that class ovveride the tabBar didSelect method from their on select of any tab you can popViewController
class TabBarViewController: UITabBarController {
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
let navigationController1 = self.viewControllers![0] as? UINavigationController
navigationController1!.popViewController(animated: false)
let navigationController2 = self.viewControllers![1] as? UINavigationController
navigationController2!.popToRootViewController(animated: false)
let navigationController3 = self.viewControllers![2] as? UINavigationController
navigationController3!.popToRootViewController(animated: false)
let navigationController4 = self.viewControllers![3] as? UINavigationController
navigationController4!.popToRootViewController(animated: false)
}
}
It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:59
add a screenshot of your storyboard in the question
– harshal jadhav
Apr 28 '17 at 11:00
ViewControllers are programmatically added to UITabBarController. But I guess it doesn't matter wether you are using Storyboard and Programatic way.
– Gaurav Borole
Apr 28 '17 at 11:05
add a comment |
up vote
0
down vote
up vote
0
down vote
You can create a UITabBarController class for your tabBar and in that class ovveride the tabBar didSelect method from their on select of any tab you can popViewController
class TabBarViewController: UITabBarController {
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
let navigationController1 = self.viewControllers![0] as? UINavigationController
navigationController1!.popViewController(animated: false)
let navigationController2 = self.viewControllers![1] as? UINavigationController
navigationController2!.popToRootViewController(animated: false)
let navigationController3 = self.viewControllers![2] as? UINavigationController
navigationController3!.popToRootViewController(animated: false)
let navigationController4 = self.viewControllers![3] as? UINavigationController
navigationController4!.popToRootViewController(animated: false)
}
}
You can create a UITabBarController class for your tabBar and in that class ovveride the tabBar didSelect method from their on select of any tab you can popViewController
class TabBarViewController: UITabBarController {
override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
let navigationController1 = self.viewControllers![0] as? UINavigationController
navigationController1!.popViewController(animated: false)
let navigationController2 = self.viewControllers![1] as? UINavigationController
navigationController2!.popToRootViewController(animated: false)
let navigationController3 = self.viewControllers![2] as? UINavigationController
navigationController3!.popToRootViewController(animated: false)
let navigationController4 = self.viewControllers![3] as? UINavigationController
navigationController4!.popToRootViewController(animated: false)
}
}
answered Apr 28 '17 at 10:44
harshal jadhav
2,6352822
2,6352822
It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:59
add a screenshot of your storyboard in the question
– harshal jadhav
Apr 28 '17 at 11:00
ViewControllers are programmatically added to UITabBarController. But I guess it doesn't matter wether you are using Storyboard and Programatic way.
– Gaurav Borole
Apr 28 '17 at 11:05
add a comment |
It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:59
add a screenshot of your storyboard in the question
– harshal jadhav
Apr 28 '17 at 11:00
ViewControllers are programmatically added to UITabBarController. But I guess it doesn't matter wether you are using Storyboard and Programatic way.
– Gaurav Borole
Apr 28 '17 at 11:05
It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:59
It works for tabs which are visible at bottom, but doesn't work for More Tab :(
– Gaurav Borole
Apr 28 '17 at 10:59
add a screenshot of your storyboard in the question
– harshal jadhav
Apr 28 '17 at 11:00
add a screenshot of your storyboard in the question
– harshal jadhav
Apr 28 '17 at 11:00
ViewControllers are programmatically added to UITabBarController. But I guess it doesn't matter wether you are using Storyboard and Programatic way.
– Gaurav Borole
Apr 28 '17 at 11:05
ViewControllers are programmatically added to UITabBarController. But I guess it doesn't matter wether you are using Storyboard and Programatic way.
– Gaurav Borole
Apr 28 '17 at 11:05
add a comment |
up vote
0
down vote
Use viewControllers
property of UITabbarController
. viewControlers is an array of UIViewController for UITabbarController. Exchange/Move position of view controllers upon tabbar(controller) selection.
Use tabbar(controller)'s delegate method to hanlde these operations, like:
Swift 3
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if var viewcontrollers = tabBarController.viewControllers {
viewcontrollers.remove(at: tabBarController.selectedIndex)
viewcontrollers.insert(viewController, at: 0)
tabBarController.viewControllers = viewControllers
}
}
You can also use this delegate method, if you have an access to tabbarController where you have implemented.
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
// Write a similar code to exchange/move view controllers using tabbarController instance.
}
add a comment |
up vote
0
down vote
Use viewControllers
property of UITabbarController
. viewControlers is an array of UIViewController for UITabbarController. Exchange/Move position of view controllers upon tabbar(controller) selection.
Use tabbar(controller)'s delegate method to hanlde these operations, like:
Swift 3
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if var viewcontrollers = tabBarController.viewControllers {
viewcontrollers.remove(at: tabBarController.selectedIndex)
viewcontrollers.insert(viewController, at: 0)
tabBarController.viewControllers = viewControllers
}
}
You can also use this delegate method, if you have an access to tabbarController where you have implemented.
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
// Write a similar code to exchange/move view controllers using tabbarController instance.
}
add a comment |
up vote
0
down vote
up vote
0
down vote
Use viewControllers
property of UITabbarController
. viewControlers is an array of UIViewController for UITabbarController. Exchange/Move position of view controllers upon tabbar(controller) selection.
Use tabbar(controller)'s delegate method to hanlde these operations, like:
Swift 3
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if var viewcontrollers = tabBarController.viewControllers {
viewcontrollers.remove(at: tabBarController.selectedIndex)
viewcontrollers.insert(viewController, at: 0)
tabBarController.viewControllers = viewControllers
}
}
You can also use this delegate method, if you have an access to tabbarController where you have implemented.
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
// Write a similar code to exchange/move view controllers using tabbarController instance.
}
Use viewControllers
property of UITabbarController
. viewControlers is an array of UIViewController for UITabbarController. Exchange/Move position of view controllers upon tabbar(controller) selection.
Use tabbar(controller)'s delegate method to hanlde these operations, like:
Swift 3
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
if var viewcontrollers = tabBarController.viewControllers {
viewcontrollers.remove(at: tabBarController.selectedIndex)
viewcontrollers.insert(viewController, at: 0)
tabBarController.viewControllers = viewControllers
}
}
You can also use this delegate method, if you have an access to tabbarController where you have implemented.
func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
// Write a similar code to exchange/move view controllers using tabbarController instance.
}
edited Mar 1 at 9:50
answered Apr 28 '17 at 10:47
Krunal
35.6k20130156
35.6k20130156
add a comment |
add a comment |
up vote
0
down vote
This worked for me.
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
guard let navigationController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController else {
return
}
navigationController.popToRootViewController(animated: false)
}
add a comment |
up vote
0
down vote
This worked for me.
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
guard let navigationController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController else {
return
}
navigationController.popToRootViewController(animated: false)
}
add a comment |
up vote
0
down vote
up vote
0
down vote
This worked for me.
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
guard let navigationController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController else {
return
}
navigationController.popToRootViewController(animated: false)
}
This worked for me.
func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
guard let navigationController = tabBarController.viewControllers?[tabBarController.selectedIndex] as? UINavigationController else {
return
}
navigationController.popToRootViewController(animated: false)
}
answered Nov 10 at 21:27
Simon Mo
62839
62839
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43678076%2fhow-to-reset-tab-or-tab-controller-of-uitabbarcontroller-when-user-select-tab%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
what have you tried already? show some code, show what errors your getting or explain it in more detail
– Scriptable
Apr 28 '17 at 10:37
@Scriptable I tried to reset navigation controllers in method tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController)
– Gaurav Borole
Apr 28 '17 at 10:41