我正在做一个带有导航栏的应用程序,它将在第一个和第三个视图之间切换(第二个和第一个将由选项卡栏切换)。
在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];
}
我的应用程序代表看起来像这样:
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;
但是它不起作用,当我单击按钮时,没有任何反应。知道吗?提前谢谢你。
您应该将
按钮的选择器保留为 goToThirdView:,但使该方法如下所示:
- (void)goToThirdView:(id)sender {
ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self.navigationController pushViewController:thirdViewController animated:YES];
}