How did iOS set UIViewController's view frame before shown?

ios, uiview, uiviewcontroller

Solution

You've got this all wrong - you really need to read (and understand) Apple's `UIViewController` docs:

View Controller Catalog

View Controller Programming Guide

View Controller Reference

If you're creating a view in code for a view controller, you should do it in the view controller's `loadView` method.

Directly from Apple's documentation:

Creating a View Programmatically

If you prefer to create views programmatically ... you do so by overriding your view controller’s loadView method. Your implementation of this method should do the following:

Create a root view object. The root view contains all other views associated with your view controller. You typically define the frame for this view to match the size of the app window, which itself should fill the screen. However, the frame is adjusted based on how your view controller is displayed. See “View Controller View Resizing.”

You can use a generic UIView object, a custom view you define, or any other view that can scale to fill the screen.

Create additional subviews and add them to the root view. For each view, you should do the following:

Create and initialize the view. For system views, you typically use the initWithFrame: method to specify the initial size and position of the view. Add the view to a parent view using the addSubview: method. Assign the root view to the view property of your view controller.

Problem

I am not familiar with iOS UIViewController's detail implement. I have the following code to create a new UIViewController and show it, but the frame I set during initWithFrame method does not worked, the controller's view always is fullscreen(320*480). ``` UIViewController *viewController = [[UIViewController alloc] init]; // view UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 140, 130)]; viewController.view = view; [view release]; AppController *app = (AppController*)[[UIApplication sharedApplication] delegate]; UINavigationController *nav = [app navController]; [nav pushViewController:viewController animated:YES]; [viewController release]; ``` I search releative thoughts in apple developer documents, but I found nothing useful for this. How did UIViewController deal with its view frame property before show it? Where can I found useful documentation. Thank you. Update: In fact, the code is from cocos2d-iphone DirectorTest: https://github.com/cocos2d/cocos2d-iphone/blob/release-2.0-rc1/tests/DirectorTest.m#L143

Original source