Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show ViewController from a non-ViewController helper class?

Usually we call self.presentViewController(...) from some UIViewController object, but how to show a new view controller from a class type (static) function in a helper class which is not a UIViewController.

like image 234
Atharva Avatar asked Feb 04 '15 05:02

Atharva


1 Answers

You can show your viewController from helper class as root view controller of navigationcontroller

UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];

UINavigationController *controller = (UINavigationController*)[storyBoard
                                                               instantiateViewControllerWithIdentifier: @"RootNavigationController"]; //set storyboard ID to your root navigationController.

YourViewController *vc = [storyBoard instantiateViewControllerWithIdentifier:@"YourViewController"]; // //set storyboard ID to viewController.
[controller setViewControllers:[NSArray arrayWithObject:vc] animated:YES];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
appDelegate.window.rootViewController=controller;
like image 153
Mayank Jain Avatar answered Sep 22 '22 00:09

Mayank Jain