如何访问tabBar点击从另一个viewController

如何访问tabBar点击从另一个viewController

问题描述:

我的主页是一个tabbarView,现在,我有一个presentModalView控制器,并且我们知道modalview需要全屏,现在这个视图有按钮,点击我想解雇modalview并选择我的主页的第二个选项卡,所以我该怎么做。如何访问tabBar点击从另一个viewController

感谢和问候 兰吉特

让我们假设你的TabbarController实例中的appDelegate。当你关闭modalView时,你发布了一个通知。你的应用程序委托将观察这个通知,当它接收到它时,它会调用[myTabController setSelectedIndex:2];以下可能是代码:

// 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]; 
} 
+0

嘿Ved非常感谢你的作品像魅力, – Ranjit

这里u必须使用tabbarcontroller的AppDelegate类对象恰克指数或标签 尝试以下

​​

例如

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

[appdelegate.tabBarController setSelectedIndex:2]; 

我有GET粗略的代码可能会给出错误,所以请检查它

编辑

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

[appdelegate.tabBarController setSelectedViewController:[appdelegate.tabBarController.viewControllers objectAtindex:1]]; 
+0

好,谢谢NIKHIL,我会检查它 – Ranjit

+0

- (无效)menuTab { [自dismissModalViewControllerAnimated:YES]; MenuViewController * menuView = [[MenuViewController alloc] initWithNibName:@“MenuView”bundle:nil]; [self.tabBarController setSelectedViewController:menuView]; [self.tabBarController setSelectedIndex:2]; } – Ranjit

+0

但它不工作,米无法去第二个选项卡上的视图,,所以请帮助我 – Ranjit