Why the view can not be added into superview?

Just want to add a subview into navigationbar, but always failed.Finally I have found the reason, but I don't know why.

In the AppDelegate.m's 

- (BOOL)application:didFinishLaunchingWithOptions:

I have added a mainviewcontroller as instance.

NavController *navigationController = [[NavController alloc] init];
MainViewController *controller = [[MainViewController alloc] init];

NSLog(@"frame: %@", NSStringFromCGRect([controller view].frame)); // ???

// **** set root view controller
[navigationController initWithRootViewController:controller];

//    NSLog(@"frame: %@", NSStringFromCGRect([controller view].frame)); // ???
    [controller release];
    [self.window addSubview:navigationController.view];    
    [self.window makeKeyAndVisible];



for this code:
NSLog(@"frame: %@", NSStringFromCGRect([controller view].frame)); // ???
if I added it below the controller init method, the subview in mainviewcontroller's navigationbar will not be added, but if I added the code below the initRootViewController method, the subview can be aded.

How is it? I really don't know why.

Thanks,

Blues








你可能感兴趣的:(Why the view can not be added into superview?)