简体   繁体   中英

How do I trigger a segue to show a specific view, when not in a UIViewController?

In my iOS app, I have a socket server that communicates with an online app; sometimes events occur online, and I need to modify the view on the connected handset. I have 3-4 View Controllers in my app, one of which is "Login". I need for example, to be able to kick people back to Login, from any of the other views.

How, from a 'not a UIViewController' class, do I "show a view" with a specific ID programmatically?

Thanks for your help.

You still should "show a view" from a view controller class. The question should be - how do I get notification about something that happened outside?

And the answer for that would be to use iOS NSNotificationCenter and NSNotification classes to broadcast something within your application. See Apple reference for NSNotificationCenter:

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSNotificationCenter_Class/

Check out unwind segues. These are specifically for this type of behavior. This will allow you to pop back easily to any viewController in the stack via a segue.

http://www.cocoanetics.com/2014/04/unwinding/

Generally you would utilize a protocol / delegate for this type of scanario to call back to the another class which is also another option.

http://www.tutorialspoint.com/ios/ios_delegates.htm

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