简体   繁体   English

iPhone UINavigationController后退按钮丢失

[英]iPhone UINavigationController Back Button Missing

In am currently creating a Navigation-based application for the iPhone, where the root view of the NavigationController is the main menu (home). 在当前正在为iPhone创建基于导航的应用程序中,其中NavigationController的根视图是主菜单(主页)。 There are 3 other views (named View1, View2 and View3), which can be accessed in this manner; 还有3个其他视图(分别名为View1,View2和View3),可以通过这种方式访问​​它们。 main menu -> View1 -> View2 -> View3. 主菜单-> View1-> View2-> View3。

Each of the Views has a 'Home button' that will call 'popToRootViewControllerAnimated' and return to the main menu. 每个视图都有一个“主页”按钮,它将调用“ popToRootViewControllerAnimated”并返回到主菜单。 When this button is pressed in View2, it returns to the main menu. 在View2中按下此按钮时,它将返回到主菜单。 However, when you go from the main menu to View1, the Back button will be missing. 但是,当您从主菜单转到View1时,“后退”按钮将丢失。 This is the only View that suffers from the problem. 这是唯一受此问题困扰的视图。

The thing that has brought this around is that we are 'lazily initialising' View1. 导致这种情况的原因是我们正在“延迟初始化” View1。 In other words, we are keeping a reference to View1 in the main menu so that we have it constantly at hand (to keep the state of that view). 换句话说,我们在主菜单中保留了对View1的引用,这样我们就可以经常使用它(以保持该视图的状态)。

The weird thing is that this problem only happens by pressing the 'Home button' from View2. 奇怪的是,仅通过按View2中的“主页”按钮会发生此问题。 With View3 there is no issue. 使用View3不会有问题。

In each of the views' 'ViewWillAppear' methods, we have the following code that will add a back button to the view's NavigationBar; 在每个视图的“ ViewWillAppear”方法中,我们都有以下代码,这些代码将向视图的NavigationBar添加后退按钮;

[self.navigationItem.backBarButtonItem release];
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
self.navigationItem.backBarButtonItem = backButton;

Does anyone have any idea on how to remedy this problem? 是否有人对如何解决此问题有任何想法?

您必须在以前的视图控制器中应用此代码,因为后退按钮取决于导航堆栈中可见视图控制器上方的视图控制器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM