Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back Navigation Button Not Showing up in Pushed View Controller

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.

like image 676
Paul Ward Avatar asked Aug 06 '10 03:08

Paul Ward


People also ask

How do I go back to the previous view controller in Objective C?

To go one view back, use below code. This will ensure that the smooth transition between views are retained. UINavigationController *navigationController = self. navigationController; [navigationController popViewControllerAnimated:NO]; [navigationController popViewControllerAnimated:YES];

How do I add a navigation controller view?

Step 1: Embed root view controller inside a navigation controller. In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .


2 Answers

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.

like image 123
Shaggy Frog Avatar answered Oct 20 '22 23:10

Shaggy Frog


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";
like image 31
Pudgeball Avatar answered Oct 21 '22 01:10

Pudgeball