UINavigationBar 未在“返回”上更新;在风景中
我正在开发 UINavigationController 驱动的 iPad 应用程序(在模拟器中测试)。导航控制器堆栈上只有两个 UIViewController。为了演示,我们将它们称为“SetupController”和“ContentController”。 SetupController 将 ContentController 压入堆栈,并
[self.navigationController pushViewController:contentController animated:YES];
在查看内容时,您可以按后退按钮返回到设置控制器。如果应用程序处于纵向模式,则一切正常。
然而,当应用程序处于横向状态并且我按下后退按钮时,事情就会变得混乱。视图控制器堆栈已正确更新(例如,我看到SetupController 的视图),但UINavigationBar 未正确更新。与 ContentController 关联的 UINavigation 栏项目仍会显示。要查看 SetupCotroller 预期的 UINavigationBar 项目,我必须再次按后退按钮,此时 UINavigationBar 会动画到正确的状态。同样,这只发生在横向模式下,纵向模式下效果很好。
作为一个测试。在 [SetupController viewDidAppear:] 方法中,我添加了以下调试输出,
if(self.navigationController.navigationBar.topItem != self.navigationItem) {
NSLog(@"wrong nav item!");
} else {
NSLog(@"correct nav item!");
}
每当模拟器处于横向模式时,我都会收到“错误”消息,而当模拟器处于纵向模式时,则不会收到“错误”消息。我尝试从 ViewController 以及我正在修改其导航项或导航栏本身的任何实例中删除所有 viewDidAppear: 消息。
有什么想法吗?我假设我在这里做错了什么,但这对我来说确实感觉像是一个错误。
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.
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.
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!");
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我遇到了同样的问题。这很奇怪,但您需要确保堆栈中的所有视图控制器都实现了以下功能(即使所有内容都正确旋转显示):
返回是;
}
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):
return YES;
}