iPhone UINavigationController Back Button Missing

半腔热情 提交于 2019-12-23 05:15:00

问题


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.

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.

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).

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

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?


回答1:


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.



来源:https://stackoverflow.com/questions/3729765/iphone-uinavigationcontroller-back-button-missing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!