0

my home page is a tabbarView,now ,I have a presentModalView Controller,and as we know modalview takes the full screen,now this view has button,on click of which I want to dismiss the modalview and select 2nd tab of my home page so how can i do it.

thanks and Regards Ranjit

Ranjit
  • 4,576
  • 11
  • 62
  • 121

2 Answers2

4

Let's assume your TabbarController instance is in appDelegate. When you dismiss the modalView, you post a notification. Your app delegate will be observing this notification and when it receives it, it will call [myTabController setSelectedIndex:2]; Following could be the code:

// modalViewController
-(void)dismiss
{
   //your regular code
   [[NSNotificationCenter defaultCenter] postNotificationName:@"modalDismissed" object:nil];
}
//appDelegate
-(void)applicationDidFinish....
{
  //your regular code
  [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectAnotherTab)   name:@"modalDismissed" object:nil];
}
-(void)selectAnotherTab
{
   [myTabController setSelectedIndex:2];
}
Ved
  • 612
  • 6
  • 10
0

here u have to use appdelegate class object of tabbarcontroller to chage index or tab try following

 [self.tabBarController setSelectedViewController:<#(UIViewController *)#>];
 or
  [self.tabBarController setSelectedIndex:<#(NSUInteger)#>];

for example

app_appAppDelegate *appdelegate=(app_appAppDelegate *)[[UIApplication sharedApplication]delegate];

[appdelegate.tabBarController setSelectedIndex:2];

i have get the rough code may give error so please check it

EDIT

 app_appAppDelegate *appdelegate=(app_appAppDelegate *)[[UIApplication  sharedApplication]delegate];

[appdelegate.tabBarController  setSelectedViewController:[appdelegate.tabBarController.viewControllers objectAtindex:1]];
NIKHIL
  • 2,719
  • 1
  • 26
  • 50
  • -(void)menuTab { [self dismissModalViewControllerAnimated:YES]; MenuViewController *menuView =[[MenuViewController alloc]initWithNibName:@"MenuView" bundle:nil]; [self.tabBarController setSelectedViewController:menuView]; [self.tabBarController setSelectedIndex:2]; } – Ranjit Oct 10 '11 at 07:47
  • but its not working ,m not able to go the view which is on second tab,,so please help me out – Ranjit Oct 10 '11 at 07:48
  • @Ranjit Add -Edit part of the code before [self dismissModalViewControllerAnimated:YES]; – NIKHIL Oct 10 '11 at 08:57