问题 横向模式下的UINavigationController导航堆栈问题


我有一个iPhone应用程序,我目前正在转换为 通用二进制 使用iPad。我已成功实现了我在布局方面所需的一切,以便我的应用程序现在支持完整的横向功能(之前我主要使用纵向模式来显示内容)。

但是,我有一个奇怪的问题,它只发生在横向模式:当我将视图控制器推入堆栈时,它需要 后面的按钮上有两个水龙头 返回上一个视图控制器!第一次点击显示空白视图,但在左侧后退导航按钮上使用相同的名称,第二次点击将控制器恢复到之前的视图。

我没有iPad来测试,所以我依靠的是模拟器。问题不会出现在iPhone上,如果您旋转回纵向模式则不会显示。

我的应用程序包含一个tabbarcontroller,其导航控制器为其vc加载:

//application delegate
- (void)applicationDidFinishLaunching:(UIApplication *)application
//....
WebHelpViewController *vc8 = [[WebHelpViewController alloc] init];
UINavigationController *nv8 = [[UINavigationController alloc] initWithRootViewController:vc8];

[self.tabBarController setViewControllers:[NSArray arrayWithObjects:nv1,nv2,nv3,nv4,nv5,nv6,nv7,nv8,nil]];

要实现格局功能,将覆盖UITabBarController以在需要时自动旋转:

//CustomTabBarController.m
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return [[(UINavigationController *)self.selectedViewController topViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

... 工作正常。我使用此方法导航到新视图

SomeViewController *vc = [[SomeViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
[vc release];

这只是模拟错误吗?我该如何解决这个问题?


4553
2018-04-22 21:23


起源



答案:


听起来像另一个 ViewController 正在回应:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

先检查一下。


10
2018-04-22 21:31



谢谢伙伴,这就是问题所在。我需要确保我所有的ViewControllers都实现了 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; - David F
如果你正在使用 CMD+N 创造新的 UIViewControllers 在XCode中,此方法是作为模板一部分包含的默认值之一。 - Sneakyness
grrr我面临着同样的问题:我将导航控制器呈现为模态,然后推送一些ViewControllers。 navController和所有推送的控制器返回YES到shouldAutorotateToInterfaceOrientation,但在横向,我需要按两次“返回”以使导航栏正确更新:/任何想法? - yonel
哼,我没有为默认控制器覆盖此方法:/导致问题。 - yonel
噢,伙计,你救了我这么多时间。谢谢! - Pyro2927


答案:


听起来像另一个 ViewController 正在回应:

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

先检查一下。


10
2018-04-22 21:31



谢谢伙伴,这就是问题所在。我需要确保我所有的ViewControllers都实现了 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation; - David F
如果你正在使用 CMD+N 创造新的 UIViewControllers 在XCode中,此方法是作为模板一部分包含的默认值之一。 - Sneakyness
grrr我面临着同样的问题:我将导航控制器呈现为模态,然后推送一些ViewControllers。 navController和所有推送的控制器返回YES到shouldAutorotateToInterfaceOrientation,但在横向,我需要按两次“返回”以使导航栏正确更新:/任何想法? - yonel
哼,我没有为默认控制器覆盖此方法:/导致问题。 - yonel
噢,伙计,你救了我这么多时间。谢谢! - Pyro2927