开发者

A question about [UIViewController alloc]

I am going through some sample code from Apple. The following 5 statements are from MoveMeAppDelegate.m belonging to the "MoveMe" sample project:

UIViewController *aViewController = [[UIViewController alloc] initWithNibName:@"MoveMeView" bundle:[NSBundle mainBundle]];

self.viewController = aViewController;
[aViewController release];

UIView *controllersView = [viewController view];
[window addSubview:controllersView];

From documentation, @"MoveMeView" defines the name of a xib file. But it seems that a xib file can have more than one view object. And in the last statement above, the controllersView is added to a window 开发者_如何学编程object. My question is if the window has more than one view, then how does the compiler know which view is the above codes referring to ?


If you're asking how your app knows which view is the controller's view: in your .xib file, you "attach" one of the views to the controller. This relationship is called an outlet, and in code is signified by the IBOutlet tag on an instance variable or on a property.

For more information, check out Apple's Resource Programming Guide--specifically, the section entitled "Nib Files."

If you're asking how the window knows which views belong to it: a window on iOS is also a view, and can have a (nearly) unlimited number of subviews.

If you're asking something else... I don't know what you're asking, so please clarify.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜