Say I do this:
@implementation currentViewController
...
SomeClass *myObject = [SomeClass alloc];
How can myObject get a reference of currentViewController without sending a message to myObject like this:
[myObject wasCreat开发者_运维知识库edIn:self];
Side note: Where do action sheets and notifications get displayed in? The current view or the appDelegate window? Does the iphone save a current hierarchy of views or do I have to keep track of it myself?
No, there's no "automagic" for this. You can create an instance of SomeClass
anywhere, and alloc/init have no idea where you're calling from unless you want to tell them by creating a property and setting it explicitly as you suggest.
This is true of all objects in general.
UIViewController
s know who their parents are, though, so if the object you're talking about is a view controller that's been pushed onto a navigation stack or presented modally from another controller, you should be able to figure out who the parent controller is.
精彩评论