在更改所选索引选项卡不起作用时关闭模态视图

时间:2012-09-06 03:22:55

标签: ios modalviewcontroller

我有一个tabBar应用程序,其菜单通过模型视图控制器调用。然后选择一个选项。我希望在更改tabBAr的SelectedIndex时忽略它。

这是我的代码片段:

FirstTabBarController:

这就是所谓的“菜单”

-(IBAction)pressedButton {

    GWDNativeViewController *secondView = [[GWDNativeViewController alloc] initWithNibName:nil bundle:nil];
    [secondView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
    [self presentModalViewController:secondView animated:YES];
}

这是在GWDNativeViewController(菜单)视图中解雇的代码:

-(IBAction)dismissThisView {

    //Insert code to dismiss here
    [self dismissModalViewControllerAnimated:YES];
    [(UITabBarController *)self.parentViewController setSelectedIndex:3];

}

该行:

[(UITabBarController *)self.parentViewController setSelectedIndex:3];

似乎没有做到这一点..

1 个答案:

答案 0 :(得分:1)

试试这个:

YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];

appDelegate.tabBarController.selectedIndex = 3;