iPhone UINavigationController Back Button Missing
In am currently creating a Navigation-based application for 开发者_JAVA技巧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?
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.
精彩评论