Created
February 20, 2016 14:01
-
-
Save 32teeth/8058ee5c04b4bc547739 to your computer and use it in GitHub Desktop.
switch between view controllers without segues
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
/* | |
** in your header, define a reference | |
*/ | |
- (void)switchViewController:(UIViewController*)view :(NSString*)segue; |
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
/* | |
** 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]; | |
} |
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
@property (strong, nonatomic) AppDelegate* delegate; | |
- (IBAction)openMenu:(id)sender; |
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
#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