Jonathan
Jonathan

Reputation: 1508

Presenting modal view controller from NSObject

I have a custom class (NSObject) that is constantly running in the background. At some point, it pops up a UIAlertView where the user has two options. The custom class is the delegate of the UIAlertView, and therefore handles the button press.

If the user presses a specific button, I'd like to present a modal view controller to the user. My problem is, this is all being handled from an NSObject. It is not being handled from a UIViewcontroller, so I can't think of a way to present this new View Controller from this parallel running NSObject.

Do I need to somehow figure out which VC is currently on top and active in order to present a new VC on top of it?

Upvotes: 0

Views: 2001

Answers (1)

Adam Johnson
Adam Johnson

Reputation: 2216

Basically you would need to access a reference to your navigation controller (assuming you have one) or something similar from say the AppDelegate in order to present the view controller. Something like the following:

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate.navigationController presentViewController:myNewViewController animated:YES completion:nil];

Upvotes: 7

Related Questions