views:

408

answers:

2

I'm pushing a tableview in a navigation based app. The pushing view (viewOld) and pushed view (viewNew) are both UITableViewControllers. I have given viewNew a title from viewOld. Once viewNew appears, I see the title but no back button on the left. Shouldn't a back button appear once you give the view (viewNew) its title?

I can click the empty space on the left of the navigation bar in viewNew and I go back to viewOld. But why is the back button not visible? I am doing this in OS 3.0 but I don't think the functionality or behavior of the back button has changed from previous versions.

Pushing viewNew from viewOld:

ViewNew * viewNew = [[ViewNew alloc] initWithNibName:@"ViewNew" bundle:nil];
viewNew = @"The new view";
[self.navigationController viewNew animated:YES];
[viewNew release];
+1  A: 

The back button is the title of viewOld, unless viewOld's navigationItem has a backBarButtonItem set, which overrides it. If viewOld doesn't have a title and doesn't have a backBarButtonItem set, then the back button won't appear.

Note that if you want to set the backBarButtonItem, its target and action should both be nil.

Ed Marty
Yes - I didn't have a title for viewOld. I did try this in viewNew but do not see the text "Back": self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease]; Any ideas why that doesn't work?
4thSpace
the backBarButtonItem has to be set for viewOld, not viewNew.
Ed Marty
A: 

I had the same problem: the Back button text was hidden but it worked when pressed on the left.

So I found this:

I just saw this the other day. What I found interesting was that touching in the area of where the back button should be actually worked. I finally decided it had to do with the text of the back button. It pulls the text from the title of the parent view controller. If there is no title, there is no text for the button, and it seems Apple made it not display a button if there is no text. So, either specify a title on the parent controller, or if you don't want that, I believe you can specify the text that the back button will display (this is specified in the parent view controller, not the child).

That was all!

Fede Mika