views:

205

answers:

1

in the case of say

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
...
[window addSubview:gameController.view];
...
}

how does the view of gameController retain association to gameController? I've peaked through all of the Debugger variables and I see no association other than a boolean flag that it belongs to a view controller. so the view is passed along to a view hierarchy (wouldn't necessarily have to be off of window), yet gameController will get events such as shouldAutorotateToInterfaceOrientation . Where is this being kept track of if not as some tucked away reference in the UIView passed out of gameController.view

UIView *tmp = gameController.view;
[window addSubview:tmp];

Its obvious that gameController knows about tmp, but how does the window know about gameController after that code?

+2  A: 

UIViewController is a descendant of UIResponder and is inserted into the responder chain between the view and that view's superview. So calling nextResponder on a view managed by a UIViewController will return said instance of UIViewController.

This is how events such as shouldAutorotateToInterfaceOrientation: get passed up through the hierarchy of instances of UIResponder. A diagram showing this can be seen in figure 3.1 in the iPhone Application Programming Guide.

Daniel Tull