I am in a situation in which I need to send an object and a method name a UIViewController that might or might not be instantiated in the future. To make the matter a bit more interesting, the UIViewController will be pushed to UINavigationController after two or three additional UIViewController being pushed.
What would be the best way to do this? An ugly approach would be just relay the message package (an object and a method name) via the controllers in-between. That's ugly.
Simply subclass UINavigationController and dangle the object and method name? Maybe. Then how do I know when to clear up that message pack?
NSInvocation looks really promising in this case though. Any thought?
No no no singleton, or extern struct please.
Edit: Thanks for the comments.
@Akshay, I have thought about that. Question is what if you want to send the message package (an object and a method name) to a specific object under a particular navigationController? Further, if the target object is not instantiated, you would need to clear your singleton for later use. But then how do you know when to clear up? Using singleton is just a mess.
@Praveen-K, NSNotifcation only works for those who already exist. I said I want to send a message package to a would-be-generated object.
@PragmaOnce, I and two other team mates are designing the architecture now. Hope this explains. Please, no data center singleton.
@Sedate Alien, Exactly!
@9dan, Thanks for your input. In fact, we have NSClassFromString, NSSelectorFromString, and performSelector that we can instantiate any object and send a message to execute any method with any number of objects.
The question is how to elegantly send that message across multiple objects, in my case UIViewController? Say you are at a UIViewControl开发者_如何学Cler, and you know you would push few more UIViewControllers on top of current one. After that, you might or might not instantiate an object of a specific class and execute a method with an object. How do we do this w/o using singleton? There must be a way to handle this beautifully. I think NSInvocation has that capacity.
精彩评论