Back button not showing in UINavigationController

I have a UINavigationController setting in an AppDelegate application:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Add the navigation controller view to the window and display. [self.window addSubview:navigationController.view]; [self.window makeKeyAndVisible]; return YES; } 

In my RootViewController, I push another view onto the stack:

 //Show the deals DealViewController *dvc = [[DealViewController alloc] initWithNibName:@"DealViewController" bundle:nil]; [self.navigationController.navigationBar setHidden:NO]; [self.navigationController pushViewController:dvc animated:YES]; 

A view will appear, but there is no back button in my navigation bar. Why is this and how can I solve it?

+4
source share
5 answers

You should think of the navigation controller as a stack of navigation controllers, each of which controls a single screen full of information. You create a navigation controller with

 -(id)initWithRootViewController:(UIViewController *)rootViewController 

method. You specify the root view controller in this call. Then you add the navigation controller view as a subview to the window, as before.

If you want to show your second screen, you push another view controller on the stack using

 -(void)pushViewController:detailViewController animated:YES 

method.

+2
source

Are you setting self.title to RootViewController? Perhaps the UINavigationController does not have any text to enter the back button, so it omits it ...?

Are you setting hidesBackButton = YES or backBarButtonItem = nil in the DealViewController or does it have another leftBarButtonItem defined?

+24
source

Try the following:

 DetailViewController *detailViewController = [[DetailViewController alloc] init]; UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle : @"Back" style : UIBarButtonItemStyleDone target : nil action : nil]; self.navigationItem.backBarButtonItem = back; [self.navigationController pushViewController : detailViewController animated : YES]; [detailViewController release]; 
+4
source

Using presentModalViewController to show the navigator. Set the navagitionController navigation bar button as follows:

 [navigationController.navigationBar.topItem setLeftBarButtonItem: [[[UIBarButtonItem alloc] initWithTitle: @"Back" style: UIBarButtonItemStylePlain target: self action: @selector(dismisstheModal:)] autorelease]]; 
+3
source

This happened to me because in the content controller of the navigation controller I configured the behavior of the navigation controller in viewDidLoad , and in another class that inherits from my content controller and the one that was presented, I implemented viewDidLoad and forgot to call [super viewDidLoad] , which forced me to override the base class viewDidLoad , where I set up my navigation controller buttons. Oooops.

0
source

Source: https://habr.com/ru/post/1340554/


All Articles