[英]Navigation bar not changing views
I'm doing an app with a Nav bar which will switch between the first and third views (the second and the first ones will be switched by a tab bar). 我正在做一个带有导航栏的应用程序,该导航栏将在第一视图和第三视图之间切换(第二和第一视图将通过标签栏进行切换)。
In the FirstViewController.h: 在FirstViewController.h中:
@property(strong,nonatomic) ThirdViewController *thirdViewController;
In the viewDidLoad method of the FirstViewController I made it: 在FirstViewController的viewDidLoad方法中,我做到了:
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Model"
style:UIBarButtonItemStylePlain target:self action:@selector(goToThirdView:)];
And also... 并且...
- (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];
}
My AppDelegate is looking like this: 我的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;
But it's not working, when I click in the button, nothing happens. 但这不起作用,当我单击按钮时,什么也没发生。 Any idea ?
任何想法 ? Thank you in advance.
先感谢您。
You should leave the selector for the button as goToThirdView:, but make that method look like this: 您应该将按钮的选择器保留为goToThirdView :,但是使该方法如下所示:
- (void)goToThirdView:(id)sender {
ThirdViewController *thirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];
[self.navigationController pushViewController:thirdViewController animated:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.