So I created a UINavigationController manually, set it as my UIWindow's rootViewController, and I would like to use a back button to exit the UINavigationController and load another viewController in its place. However, the backItem property of the UINavigationBar is readonly, so I don't know how to set it properly (it is readonly and defaults to nil in the root navigation view). How can I achieve this (or similar effect, I want to be able to effectively "exit" this UINavigationController by pressing the back button on the root view).
Alternatively, is this bad form? How should I escape the root view of a UINavigationController?
EDIT:
Attempted Legolas' solution with the following code: (some names have been changed)
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:plvc]; // plvc being the first viewcontroller
MyAppDelegate* appDelegate = [Utility getAppDelegate];
appDelegate.window.rootViewController = navController;
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithTitle:@"Start" style:UIBarButtonItemStyleBordered target:self action:@selector(initializeStuff)];
navController.navigationItem.leftBarButtonItem = backButton;
[navController.navigationItem setHidesBackButton:YES animated:YES];
[navController.view setNeedsDisplay];
But the button does not display. What am I doing wrong? The other back buttons display properly, but this one still does not.
You can do this in a different approach.
Go to the method:
Hide the back button with
Create a new UIButton or a UIBarButtonItem, and place it in place of the back button.
You can then use an action when you click the button
Updating my answer: Use this in the viewDidLoad method //works like a charm //
There are a few approaches I can think of.
leftBarButtonItem
.leftBarButtonItem
.UINavigationController
stack. The sole purpose of this root view will be to launch the secondary view, or die when the user comes back to it. This way, you will never seeUINavigationController
without a back button. I've tested this (but not profiled it); performance impact seems negligible.Also, check out <https://discussions.apple.com/message/8298537#8298537> from 2008. Same question.
To which someone replied:
try dis:-