Question

Something happens in my datamodel, and I need to present a modal viewcontroller instantiated through the storyboard.

How can I do this? I need to present a modal VC from an NSObject, and obviously presentViewController is a UIViewController method.

What's the best way to do this?

UIStoryboard *mainStoryboard = [(AppDelegate *) [[UIApplication sharedApplication] delegate] storyboard];

NewMessageListenPopupVC *popupVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"NewMessageListenPopupVC"];

[self presentViewController:popupVC animated:YES completion:nil];

EDIT:

Code I am probably going to end up using:

UIStoryboard *mainStoryboard = [(AppDelegate *) [[UIApplication sharedApplication] delegate] storyboard];

NewMessageListenPopupVC *popupVC = [mainStoryboard instantiateViewControllerWithIdentifier:@"NewMessageListenPopupVC"];

UIViewController *rootVC = [[(AppDelegate *) [[UIApplication sharedApplication] delegate] window] rootViewController];
[rootVC presentViewController: popupVC animated:YES completion:nil];
Was it helpful?

Solution

rYou could do this by getting the rootView controller from the window of the application and then calling presentViewController on that VC.

UIViewController *vc = [window rootViewController];
[vc presentViewController: yourVC animated:YES completion:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top