views:

38

answers:

1

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 wasCreatedIn: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?

+2  A: 

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.

UIViewControllers 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.

quixoto
Further info: Remember that objects can even be created in a context where no self exists at all. Objective-C is not purely object-oriented!
Chuck