Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A sample view controller that is used to link storyboards via segues.
//
// WPSStoryboardLinkViewController.h
//
// Created by Kirby Turner on 5/4/13.
//
//
#import <UIKit/UIKit.h>
@interface WPSStoryboardLinkViewController : UIViewController
/// The name of the storyboard that should be linked.
/// This should be set in the Interface Builder identity inspector.
@property (nonatomic, copy) NSString * storyboardName;
/// (Optional) The identifier of the scene to show.
/// This should be set in the Interface Builder identity inspector.
@property (nonatomic, copy) NSString * sceneIdentifier;
@end
//
// WPSStoryboardLinkViewController.m
//
// Created by Kirby Turner on 5/4/13.
//
//
#import "WPSStoryboardLinkViewController.h"
@interface WPSStoryboardLinkViewController ()
@end
@implementation WPSStoryboardLinkViewController
- (void)awakeFromNib
{
[super awakeFromNib];
NSString *storyboardName = [self storyboardName];
NSString *sceneIdentifier = [self sceneIdentifier];
NSAssert([storyboardName length], @"No storyboard name");
UIStoryboard * storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];
UIViewController * scene = nil;
if ([sceneIdentifier length] == 0) {
scene = [storyboard instantiateInitialViewController];
} else {
scene = [storyboard instantiateViewControllerWithIdentifier:sceneIdentifier];
}
NSAssert(scene, @"No scene found in storyboard: \"%@\" with identifier: \"%@\"", storyboardName, sceneIdentifier);
UINavigationController *navigationController = [self navigationController];
if ([scene isKindOfClass:[UINavigationController class]]) {
scene = [(UINavigationController *)scene topViewController];
}
[navigationController pushViewController:scene animated:NO];
NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:[navigationController viewControllers]];
[viewControllers removeObject:self];
[navigationController setViewControllers:viewControllers animated:NO];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.