2011-10-14 81 views
1
self.window.rootViewController = self.tabBarController; 
[self.window addSubview:self.tabBarController.view]; 

它们在下面的上下文中使用:下面两条陈述有什么区别?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    // Add the tab bar controller's current view as a subview of the window 


    // self.window.rootViewController = self.tabBarController; 
    [self.window addSubview:self.tabBarController.view]; 

    IntroViewController *introViewController = [[IntroViewController alloc] initWithNibName:@"IntroViewController" bundle:nil]; 

    //Lets place introViewController in navController 
    UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:introViewController]; 

    //Now lets display it 
    [self.tabBarController presentModalViewController:navController animated:YES]; 

    [navController release]; 
    [introViewController release]; 


    [self.window makeKeyAndVisible]; 
    return YES; 
} 

回答

0

iOS Reference

RootViewController的

根视图控制器提供窗口的内容图。 将视图控制器分配给此属性(编程为 或使用Interface Builder)将视图控制器的视图安装为窗口的内容视图 。如果该窗口具有现有视图 层次结构,则在安装新视图之前删除旧视图。

addSubview

此方法保留视图,并将其下一个应答器的接收器, 这是它的新上海华。

视图只能有一个超级视图。如果视图已经有超级视图并且该视图不是接收者,则在使接收者成为新的超级视图之前,该方法移除先前的超级视图。

因此,我们可以说,主要的区别在于设置RootViewController的销毁所有包含在UIWindow以前的意见,并使用addSubView:只增加顶部的UIView

0

self.window.rootViewController = self.tabBarController;

此声明是错误的,因为窗口是一个容器,您没有任何根控制器。

SubView: [self.window addSubview:self.tabBarController.view];

Here you are adding the tabBarController as a subview which will add your windows container. And this is the right way to create the tab bar controller.