BackButtonBarItem not working properly in iphone
I implemented the following code to show the navigation bar with a backbuttonbaritem.
[mapNavigationItem setTitle:@"Tracking"];
[mapNavigationItem setRightBarButtonIte开发者_如何学编程m:nil];
[mapNavigationItem setLeftBarButtonItem:nil];
UIBarButtonItem *stopTrackingBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Stop Tracking" style:UIBarButtonItemStylePlain target:nil action:@selector(stopTracking)];
[mapNavigationItem setBackBarButtonItem:stopTrackingBarButton];
[mapNavigationBar pushNavigationItem:mapNavigationItem animated:NO];
[stopTrackingBarButton release];
The stopTracking button is displayed on the screen, but no title is displayed. When i click on the stopTracking button, it disappears and then shows the title. Could someone please tell me whats happening??
Ok i think i wasnt clear enough,
I have a mapview with buttons in the tab bar, when the app starts the navigation bar shows 2 buttons, when i click on one of the Tab bar items, it should clear the navigation bar buttons and add a back button bar button item only. I am successful upto this stage. But when i click on the BackBar button item, it disappears, and does not perform the action assigned to it.
FYI:
IBOutlet UINavigationBar *mapNavigationBar;
IBOutlet UINavigationItem *mapNavigationItem;
If you want to use a different title for your back button than the previous navigation title, then you need to change it just before pushing the new view controller and change it back again after popping it.
So something like:
self.navigationItem.title = @"Stop Tracking";
[self.navigationController pushViewController:mapNavigationItem animated:NO];
and in this class's viewWillAppear
self.navigationItem.title = @"Tracking";
Edit:
If you are not using the backbarbutton for taking the navigation controller back then dont set it as a backBarButton simply set it as left barButton item.
Plus it also seems like you are using same navigation bar for both tabs. not a good idea. Load both tab views from different viewcontrollers and add two different navigation bars to those views.
精彩评论