0

My intention is to create an App which has the Main View with UIButton to click. Once clicking one of the button will enter TabBarController View.

For example, when you click sample1 button will automatically select 2nd tab in TabBarController View. And when you click sample2 button will go to 3rd tab, more button will go to more tab which will display table view.

My problem is when I click the UITableViewCell in MoreViewController to get into detail view. But, when I want to go back to the TabBarController by clicking the upper-left button. The tab will change to the one I click in the Main View.

It seems the selectedIndex of the TabBarController didn't change, even though I set the value in the delegate method

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath

or other places like viewWillAppear viewWillDisappear in the MoreViewController, still, the value of the selectedIndex stays the same.

The sample code is here -> http://uploadingit.com/file/qxfbw4cuzjdkk56v/9s.zip

Does anybody knows how to solve this problem?

Jens Bergvall
  • 1,617
  • 2
  • 24
  • 54
Lee
  • 25
  • 7

1 Answers1

0

Actually you are pushing Your Tabbar Controller from your Main View Using the main Navigation Controller. So its taking you to the Main view at the time of POP out.

Try this for Creating Tabbar

tabBar_Controller = [[UITabBarController alloc] init];
NSMutableArray *localControllersArray =[[NSMutableArray alloc]initWithCapacity:2];


firstViewController = [[FirstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:firstViewController];
nav.tabBarItem.title = @"item1";
nav.navigationBar.barStyle = UIBarStyleBlack;
[localControllersArray addObject:nav];
[self setNav:nil];

secondViewController = [[SecondViewController alloc] initWithNibName:@"secondViewController" bundle:nil];
nav = [[UINavigationController alloc]initWithRootViewController:secondViewController];
nav.tabBarItem.title = @"item2";
[localControllersArray addObject:nav];
[self setNav:nil];

tabBar_Controller.viewControllers = localControllersArray;
tabBar_Controller.delegate = self;
tabBar_Controller.selectedIndex = 0;
[self.window addSubview:tabBar_Controller.view];
Siba Prasad Hota
  • 4,779
  • 1
  • 20
  • 40