Skip to content

Instantly share code, notes, and snippets.

@32teeth
Created February 20, 2016 14:01
Show Gist options
  • Save 32teeth/8058ee5c04b4bc547739 to your computer and use it in GitHub Desktop.
Save 32teeth/8058ee5c04b4bc547739 to your computer and use it in GitHub Desktop.
switch between view controllers without segues
/*
** in your header, define a reference
*/
- (void)switchViewController:(UIViewController*)view :(NSString*)segue;
/*
** somewhere in your app delegate
** if you feel brave, create a UIViewController category and link to it
** ex: UIViewController+switcher.h
*/
- (void)switchViewController:(UIViewController*)view :(NSString*)segue
{
NSString * name = @"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:name bundle: nil];
UIViewController *viewcontroller = [storyboard instantiateViewControllerWithIdentifier:segue];
[view presentViewController:viewcontroller animated:nil completion:nil];
}
@property (strong, nonatomic) AppDelegate* delegate;
- (IBAction)openMenu:(id)sender;
#import "AppDelegate.h"
/*
** inside viewDidLoad
*/
_delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
/*
** somewhere in your storyboard is a view controller
** with a Storyboard ID of menuViewController in this example
*/
- (IBAction)openMenu:(id)sender {
NSString *segue = @"menuViewController";
[_delegate switchViewController:self :segue ];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment