Last active
August 29, 2015 14:13
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ADModalSegue.h | |
// | |
// Created by Jeffrey Kereakoglow on 11/28/14. | |
// Copyright (c) 2014 Alexis Digital. All rights reserved. | |
// | |
@import UIKit; | |
@interface ADModalSegue : UIStoryboardSegue | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.