简体   繁体   中英

Navigating to ViewController from AppDelegate?

Is there a preferred method when, upon receiving a notification in application:didReceiveLocalNotification: , I bring the user to a certain view controller*?

For example , if I have view controllers A, B, C, and D, a notification comes in, the app is running in the background with the user at screen A, B, or C, and I need to bring them to screen D, and back to their previous screen when they're done.

One method seems to be making A, B, C delegates of D, hooking them up with segues in storyboard, and doing performSegueWithIdentifier: in application:didReceiveLocalNotification:, but that doesn't scale well if I have ex. 60 screens.

Is there a better/best way to push a view controller on the screen from the AppDelegate and go back to wherever the user was previously when they're finished?

* Note this will not occur if the user is currently inside app, so as not to be disruptive.

Normally that kind of behavior is best achieved with modal view controllers.

However I wouldn't pop a modal view controller from the appDelegate but instead I'd make A, B and C subclasses of the same class. This class would have code to handle the notification by showing a modal view controller (with D) that when dismissed will show the view controller where you were when the notification came.

Though I don't understand your last sentence. If that's not going to happen when the user is inside the app why you bother to get him back to the previous screen?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM