0

Tabbed Application テンプレートを選択します。次に、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
4

1 に答える 1

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;
}
于 2012-07-26T08:31:03.270 に答える