UINavigationBar不会在横向上更新“返回” [英] UINavigationBar not updating on 'back' in landscape

查看:116
本文介绍了UINavigationBar不会在横向上更新“返回”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个UINavigationController驱动的iPad应用程序(在模拟器中测试)。导航控制器堆栈上只有两个UIViewControllers。为了演示,我们称之为SetupController和ContentController。 SetupController使用

I'm working on a UINavigationController driven iPad app (testing in the simulator). There are only two UIViewControllers on the nav controllers stack. For demonstration, lets call them SetupController and ContentController. SetupController pushes a ContentController on the stack with

[self.navigationController pushViewController:contentController animated:YES];

在查看内容时,您可以按后退按钮返回设置控制器。如果应用程序处于纵向模式,则一切正常。

While looking at the content, you can press the back button to go back to the setup controller. If the app is in portrait mode, things work correctly.

然而,当应用程序处于横向状态并且我点击后退按钮时,情况会变得混乱。视图控制器堆栈已正确更新(例如,我看到SetupController的视图),但UINavigationBar未正确更新。仍会显示与ContentController关联的UINavigation栏项。要查看SetupCotroller的预期UINavigationBar项目,我必须再次按下后退按钮,此时UINavigationBar会动画到正确的状态。同样,这只发生在横向模式,肖像模式完美运行。

However, when the app is in landscape and I hit the back button, things go haywire. The view controller stack is updated properly (e.g. I see the SetupController's view), but the UINavigationBar is not updated properly. The UINavigation bar items associated with the ContentController are still displayed. To see the SetupCotroller's expected UINavigationBar items, I have to press the back button a second time, at which point the UINavigationBar animates to the correct state. Again, this only happens in landscape mode, portrait mode works perfectly.

作为测试。在[SetupController viewDidAppear:]方法中,我添加了以下调试输出

As a test. In the [SetupController viewDidAppear:] method I have added the following debug output

 if(self.navigationController.navigationBar.topItem != self.navigationItem) {
  NSLog(@"wrong nav item!");
 } else {
  NSLog(@"correct nav item!");
 }

当模拟器处于横向模式时,我收到错误消息,并且从来没有处于纵向模式。我已经尝试删除所有viewDidAppear:来自ViewControllers的消息以及我正在修改其导航项或导航栏本身的任何实例。

I get the "wrong" message whenever the simulator is in landscape mode, and never when it is in portrait mode. I've tried removing all viewDidAppear: messages from both ViewControllers and any instances where I'm modifying their navigation items or the navigation bar itself.

有什么想法吗?我假设我在这里做错了,但这肯定对我来说是一个错误。

Any thoughts? I'm assuming I'm doing something wrong here, but this sure feels like a bug to me.

推荐答案

我遇到了一样的问题。这很奇怪,但你需要确保堆栈中的所有视图控制器都实现了以下功能(即使所有内容都显示正确旋转):

I ran into the same problem. It's weird, but you need to make sure all of the view controllers in the stack have the following implemented (even if everything is displaying correctly rotated):


  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
    }

这篇关于UINavigationBar不会在横向上更新“返回”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆