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.
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];
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 .
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.
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With