views:

124

answers:

3

I have a problem where I can successfully push a new view controller from my root view controller (using the Navigation-based application using Core Data template), but the detail view, which is a separate xib file from the root view controller, doesn't display the back navigation button. I'm certain that I've done all of the proper connections in IB, and everything else is working as expected.

RootViewController.h

@class ItemsViewController;

@interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate> {

IBOutlet ItemsViewController *itemsVC;

}

@property (nonatomic, retain) IBOutlet ItemsViewController *itemsVC;

@end

RootViewController.m

#import "ItemsViewController.h"

@synthesize itemsVC;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
// Pushes to ItemsViewController

ItemsViewController *itemsViewController = [[ItemsViewController alloc] initWithNibName:@"ItemsViewController" bundle:[NSBundle mainBundle]];

[self.navigationController pushViewController:itemsViewController animated:YES];
[itemsViewController release];

}

ItemsViewController is a UITableViewController subclass with its own xib, also named ItemsViewController. Again, it gets pushed from RootViewController, but the back button doesn't show up like this. I was under the impression that it was a "free" feature of using a navigation controller. As you might expect, this is a very frustrating roadblock and I would appreciate any help.

+1  A: 

Does your ItemsViewController class set its title property in its viewDidLoad method?

You should call [tableView deselectRowAtIndexPath:indexPath animated:YES] as the last line of tableView:didSelectRowAtIndexPath: to conform to Apple's human interface guidelines.

Shaggy Frog
I haven't set the title yet. Its going to come from a CD name property that one enters from the RVC. Does the title need to be set for the back button to appear?
Paul Ward
True. But you should always have a title on the nav bar. How about this: are you setting the `title` in `RootViewController`'s `viewDidLoad` method? I've had problems before with the back button when the root view's title wasn't set.
Shaggy Frog
Excuse me while I pick my face up from the desk. Setting a title in the RVC gave me the back button. I guess it needs to be populated before it renders. Thanks for the tip, I won't be forgetting that anytime soon!
Paul Ward
+1  A: 

Yeah, make sure you have a title on your RootViewController, if it doesn't no button will appear. To set a title programmatically;

self.navigationItem.title = @"Hello Der";
Pudgeball
A: 

Some extra info for future readers: I ran into this problem while trying to re-populate a nav hierarchy on application load, so I was calling setViewControllers: from the app delegate's application:didFinishLaunchingWithOptions: method. And I was running into the same problem with the back button not showing up.

In my case, setting the root view controller's nav item title in its viewDidLoad did not work, presumably because the other views were loading first and seeing the root's title as null. Instead, I set the root view controller's nav item title in my application:didFinishLaunchingWithOptions: method right before I called setViewControllers:, and that fixed it.

Josh Justice