I made masterdetailview with different viewcontrollers
in my storyboard
and linked every one with push segue
. Now when I click on list item new DetailViewController
opens, but every single one have no navigationbar
. I added navigation item
on top off every View, added title for every single one, but after all that navigation bar
is not showing. I am working on iPad
app and in both orientations navigation bar is missing.
EDIT:
My appDelegate is same as template when you create your Master-Detail project:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
}
return YES;
}
One of my DetailViewControllers:
#import "MediaExpDetailViewController.h"
@interface MediaExpDetailViewController ()
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
@end
@implementation MediaExpDetailViewController
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
- (void)viewDidLoad{
[super viewDidLoad];
}
#pragma mark - Split view
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
barButtonItem.title = NSLocalizedString(@"MasterButton", @"Master");
[self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
self.masterPopoverController = popoverController;
}
- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
// Called when the view is shown again in the split view, invalidating the button and popover controller.
[self.navigationItem setLeftBarButtonItem:nil animated:YES];
self.masterPopoverController = nil;
}
@end
Your DetailViewController has to be connected to a UINavigationController. If you set up a new master-detail-project from Xcode's "New Project" menu you will get this:
Notice: Every Detail view controller has to be connected to a UINavigationController (directly or indirectly).
Edit: To connect multiple UINavigationControllers, do the following: Your initial detail views UINavigationController is connected with the split view (as usual). Every others detail views UINavigationController is connected with the master view (with a replace segue):
If you want to give the user the possibility to switch back to the initial detail view, you also have to connect the initial view controller with the master (thus having two connections, one to the split, one to the master).
To switch between detail view controllers, you call performSegueWithIdentifier:sender:
in your master view controller.
Edit 2:
To add your detail views as the split view's delegate implement the following method, which gets called earlier than viewDidLoad
- (void)awakeFromNib
{
self.splitViewController.delegate = self;
}
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