Skip to content

Instantly share code, notes, and snippets.

@jkereako
Last active August 29, 2015 14:13
Show Gist options
  • Save jkereako/9a42159cc6a902b8c4f1 to your computer and use it in GitHub Desktop.
Save jkereako/9a42159cc6a902b8c4f1 to your computer and use it in GitHub Desktop.
Don't see a navigation bar on a modally presented view controller? Here's the solution: subclass UIStoryboardSegue, override perform: and in its definition create an ad-hoc navigation controller. Then, use this custom segue in the Storyboard builder.
//
// ADModalSegue.h
//
// Created by Jeffrey Kereakoglow on 11/28/14.
// Copyright (c) 2014 Alexis Digital. All rights reserved.
//
@import UIKit;
@interface ADModalSegue : UIStoryboardSegue
@end
//
// ADModalSegue.m
//
// Created by Jeffrey Kereakoglow on 11/28/14.
// Copyright (c) 2014 Alexis Digital. All rights reserved.
//
#import "ADModalSegue.h"
@implementation ADModalSegue
-(void)perform {
UIViewController *svc = self.sourceViewController;
UIViewController *dvc = self.destinationViewController;
UINavigationController *nc;
// Create an ad-hoc navigation controller simply so we can access its
// navigation bar.
nc = [[UINavigationController alloc] initWithRootViewController:dvc];
[svc presentViewController:nc
animated:YES
completion:nil];
}
@end
@jkereako
Copy link
Author

Use with Storyboards

The Storyboard Builder is smart enough to know that any class with "segue" in the file name is, in fact, a segue.

After adding this to your project, you will be able to select it as a segue option in Storyboard Builder. This particular file will be seen as modal segue in Storyboard Builder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment