nasaa
nasaa

Reputation: 2731

UINavigationController shows but without back button

In my delegate class I have this -

BluenibViewController *mvc = [[BluenibViewController alloc] init];
UINavigationController *unvc = [[UINavigationController alloc] init];
[unvc pushViewController:mvc animated:NO];
[mvc release];
[self.window addSubview:unvc.view];
[self.window makeKeyAndVisible];
return YES;

and in my BluenibViewController I have this method -

-(IBAction) BookingsViewController:(id)sender

{
    bookingsViewController1 = [[BookingsViewController alloc]
                              initWithNibName:@"BookingsViewController"
                              bundle:nil];

UINavigationController *navController = self.navigationController;
[navController pushViewController:bookingsViewController1 animated:YES];


self.title = @"Bookings";
[self.window makeKeyAndVisible];
[self.view addSubview:bookingsViewController1.view];
[navController release];
[bookingsViewController1 release];

}

Ob click of this method I am able to go to the next view but there is no back button on the navigation bar.

Please point me to the silly mistake I am doing.

Upvotes: 0

Views: 1225

Answers (4)

Even Cheng
Even Cheng

Reputation: 1996

it comes a little bit late but in iOS 8 you can do:

[self.navigationController pushViewController:secondViewController animated:YES];

Upvotes: 0

Bajaj
Bajaj

Reputation: 869

self.navigationItem.hidesBackButton =YES;  

Follow this code . Hope it helps ....

Upvotes: 0

user537213
user537213

Reputation:

I see quite a few errors here. Lets see if I can't be of some service.

First, I see that you're overreleasing your navigation controller [navController release];

Second, you should only have to make the window key/visible once in your entire project. You set your navController as the rootViewController for your window, make it key/visible, and then you should never have to do anything with your window again. Don't think it's breaking anything, but you should remove all calls to make key/visible beyond the first.

In the end, pushing a new view controller should look like this:

[self.navigationController pushViewController:[[[BookingsViewController alloc] init] autorelease] animated:YES];

You shouldn't need anything else to get what you're looking for.

Upvotes: 2

rob mayoff
rob mayoff

Reputation: 385610

You should not add unvc.view as a subview of self.window. You should just assign unvc as self.window.rootViewController:

self.window.rootViewController = unvc;

and you should not add bookingsViewController1.view as a subview of self.view (in your BookingsViewController: method). The navigation controller will take care of getting bookingsViewController1.view onto the screen after you have pushed it.

Upvotes: 2

Related Questions