Question

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

Was it helpful?

Solution

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];
}

OTHER TIPS

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]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top