开发者

How to access tabBar click from another viewController

开发者 https://www.devze.com 2023-04-11 17:13 出处:网络
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 mo

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


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


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号