0

我正在做一个带有导航栏的应用程序,它将在第一个和第三个视图之间切换(第二个和第一个视图将由标签栏切换)。

在 FirstViewController.h 中:

@property(strong,nonatomic) ThirdViewController *thirdViewController;

在 FirstViewController 的 viewDidLoad 方法中,我做到了:

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Model"
style:UIBarButtonItemStylePlain target:self action:@selector(goToThirdView:)];

并且...

- (void)goToThirdView:(id)sender
{

    ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];

    self.thirdViewController = thirdViewController;   

    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];

    [self.view removeFromSuperview];

    [self.view insertSubview:self.thirdViewController.view atIndex:0];

    [UIView commitAnimations];

}

我的 AppDelegate 看起来像这样:

UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
UINavigationController *navigationController1 = [[UINavigationController alloc] initWithRootViewController:viewController1];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:navigationController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;

但它不起作用,当我单击按钮时,什么也没有发生。任何想法 ?先感谢您。

4

1 回答 1

0

您应该将按钮的选择器保留为 goToThirdView:,但使该方法如下所示:

- (void)goToThirdView:(id)sender {

    ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
    [self.navigationController pushViewController:thirdViewController animated:YES];

}
于 2013-09-15T05:11:00.673 回答