iPhone UINavigationController后退按钮丢失 [英] iPhone UINavigationController Back Button Missing

查看:57
本文介绍了iPhone UINavigationController后退按钮丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在为iPhone创建一个基于导航的应用程序,其中NavigationController的根视图是主菜单(主页).还有3个其他视图(分别名为View1,View2和View3),可以通过这种方式访问​​它们.主菜单-> View1-> View2-> View3.

In am currently creating a Navigation-based application for the iPhone, where the root view of the NavigationController is the main menu (home). There are 3 other views (named View1, View2 and View3), which can be accessed in this manner; main menu -> View1 -> View2 -> View3.

每个视图都有一个主页"按钮,它将调用"popToRootViewControllerAnimated"并返回主菜单.在View2中按下此按钮时,它将返回到主菜单.但是,当您从主菜单转到View1时,后退"按钮将丢失.这是唯一受此问题困扰的视图.

Each of the Views has a 'Home button' that will call 'popToRootViewControllerAnimated' and return to the main menu. When this button is pressed in View2, it returns to the main menu. However, when you go from the main menu to View1, the Back button will be missing. This is the only View that suffers from the problem.

带来这种情况的原因是我们正在延迟初始化" View1.换句话说,我们在主菜单中保留了对View1的引用,这样我们就可以经常使用它(以保持该视图的状态).

The thing that has brought this around is that we are 'lazily initialising' 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).

奇怪的是,此问题仅通过在View2中按下主页"按钮来发生.使用View3不会有问题.

The weird thing is that this problem only happens by pressing the 'Home button' from View2. With View3 there is no issue.

在每个视图的"ViewWillAppear"方法中,我们都有以下代码,这些代码将向视图的NavigationBar添加后退按钮;

In each of the views' 'ViewWillAppear' methods, we have the following code that will add a back button to the view's 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?

推荐答案

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

You must apply this code in the previous view controller, as the back button depends on the view controller above the visible view controller in the navigation stack.

这篇关于iPhone UINavigationController后退按钮丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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