4
votes

Kindly help me with this issue .

I am using tabbarcontroller in my App,

[tabBarController setViewControllers:tabs]; tabs Contain array of viewcontrollers (6 viewcontrollers).

It automatically created more button.

ISSUE

When I open any viewcontroller from more button and then open any other controller from index 0 to 2 , and then press more button it maintain the last opened viewcontroller .

For Example: more button tableviewcontroller

screen : enter image description here

Now when i press Contacts let say

enter image description here

Now when user press any other tabbar like feature tab bar

enter image description here

Now when user go back to more tab it shows the contact's viewcontroller enter image description here

But i want the app to poptorootviewcontroller when user back again to more tabbar , and simply more tableviewcontroller.

enter image description here

2
TIP: it is against the User Experience of iOS. - Adil Soomro
However +1 for good and (very long) elaboration :) - Adil Soomro
lol thank you :p ... but brother its user requirement ;( and i really not to do this - munibsiddiqui
viewWillDisappear is a valid workaround, and works, but adding it in all the viewControllers in 'More' might be cumbersome. You should take a look at UITabBarControllerDelegate. @Siby's answer below is one better solution. Overriding that method or didSelectViewController is a better way, since you get the freedom to perform any operations/actions from within a single method. - n00bProgrammer

2 Answers

2
votes

You can do this by in the ViewWillDisappear method of view controller in More tab, call method to pop this view out of MoreViewNavigationController, like this:

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController popViewControllerAnimated:NO];
}
0
votes

May be too late but here it is for future reference

UITabController has a tabBar property and it has a delegate which tells you when a tabitem is tapped

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item 

Tab bar also has another property "items" which lists the visibile tabs. Find the index of the selected tab item in items in the delegate method implementation and if the index is 4 which is more button then call tab [controller.moreNavigationController popToRootViewController]