4

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

munibsiddiqui
  • 435
  • 5
  • 15
  • TIP: it is against the User Experience of iOS. – Adil Soomro May 29 '12 at 06:13
  • However +1 for good and *(very long)* elaboration :) – Adil Soomro May 29 '12 at 06:14
  • lol thank you :p ... but brother its user requirement ;( and i really not to do this – munibsiddiqui May 29 '12 at 07:13
  • `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 Apr 09 '14 at 05:59

2 Answers2

2

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];
}
Son Nguyen
  • 3,481
  • 4
  • 33
  • 47
  • `viewWillAppear` or `viewWillDisappear`? – Adil Soomro May 29 '12 at 07:15
  • 1
    Thanks sir , its was very much use full ... but would like to correct something ' AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; if (appDelegate._tabBarController.selectedIndex < 4) { [super viewWillDisappear:animated]; [appDelegate._tabBarController.moreNavigationController popViewControllerAnimated:NO]; } ' – munibsiddiqui Jun 01 '12 at 10:49
0

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]

Kumar
  • 7
  • 5
Siby
  • 318
  • 1
  • 10