2012-07-26 93 views
0

我選擇選項卡式應用程序模板。然後我添加了CoolViewController,但它沒有出現在屏幕上。哪裏不對?我的視圖控制器沒有出現在屏幕上

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
self.tabBarController = [[UITabBarController alloc] init]; 
self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil]; 
self.window.rootViewController = self.tabBarController; 

CoolViewController *coolVC = [[CoolViewController alloc] init]; 
coolVC.view.frame = CGRectMake(0, 0, 320, 200); 
coolVC.view.backgroundColor = [UIColor blackColor]; 
[self.window addSubview:coolVC.view]; 

[self.window makeKeyAndVisible]; 
return YES; 
} 

@interface CoolViewController : UIViewController 
@end 
+0

offtopic:你使用ARC? – CarlJ 2012-07-26 08:35:47

+0

你可以嘗試:CoolViewController * coolVC = [[CoolViewController alloc] initWithNibName:@「CoolViewController」bundle:nil]; – parilogic 2012-07-26 08:36:32

回答

1

您不應該將CoolViewController添加到窗口,而是添加到UITabBarController

您應該結束了,像這樣:(注意:我還沒有嘗試過)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
self.tabBarController = [[UITabBarController alloc] init]; 

CoolViewController *coolVC = [[CoolViewController alloc] init]; 
coolVC.view.frame = CGRectMake(0, 0, 320, 200); 
coolVC.view.backgroundColor = [UIColor blackColor]; 

self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2,coolVC, nil]; 
self.window.rootViewController = self.tabBarController; 




[self.window makeKeyAndVisible]; 
return YES; 
} 
相關問題