Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back button not appearing on UINavigationController

I have a UINavigationController setup in my AppDelegate:

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

    return YES;
}

In my RootViewController I am pushing 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];

The view shows up, but there is no back button that is added to my navigation bar. Why is this and how can I resolve it?

like image 355
Sheehan Alam Avatar asked Feb 20 '11 22:02

Sheehan Alam


3 Answers

Are you setting self.title in RootViewController? Perhaps the UINavigationController doesn't have any text to put on the back button, so it omits it...?

Are you setting hidesBackButton = YES or backBarButtonItem = nil in DealViewController, or does it have a different leftBarButtonItem defined?

like image 55
Jeff Ames Avatar answered Sep 28 '22 12:09

Jeff Ames


Try this:

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];
like image 31
Ali Avatar answered Sep 28 '22 13:09

Ali


You must think of the navigation controller as a stack of navigation controllers each controlling one screen full of information. You instantiate the navigation controller with the

-(id)initWithRootViewController:(UIViewController *)rootViewController

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

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

-(void)pushViewController:detailViewController animated:YES

method.

like image 45
GorillaPatch Avatar answered Sep 28 '22 14:09

GorillaPatch