0

アップルのドキュメントを使用して、タブバーとナビゲーションを組み合わせたプログラムを実装しています。

initWithFrame、[黒い画面になる]を呼び出すと機能しません。ただし、以下のコードのままにしておくと、タブバーなしでメイン画面を表示するために機能し、タブバーを使用すると黒い画面になります

ここにコード

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(  NSDictionary *)launchOptions {                  
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
StartViewController *startViewControllerView = [[[StartViewController alloc] init] autorelease]; //ojo recomendado por apple!!!
VideosViewController* VideosViewController_ = [[[VideosViewController alloc] init] autorelease];
PhotosViewController* PhotosViewController_ = [[[PhotosViewController alloc] init] autorelease];
SocialViewController* SocialViewController_ = [[[SocialViewController alloc] init] autorelease];
self.pagesNavigation = [[[UINavigationController alloc] initWithRootViewController:startViewControllerView] autorelease];
self.pagesNavigation.navigationBarHidden = NO;
NSArray* controllers = [NSArray arrayWithObjects:VideosViewController_, PhotosViewController_, SocialViewController_, startViewControllerView, nil];
self.tabBarController.viewControllers = controllers;
[self.window addSubview:startViewControllerView.view];
//self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
[self.window makeKeyAndVisible];
  return YES;
}

したがって、上に示したままにしておくと機能しますが、addSubview をコメントして initWithFrame のコメントを外すと機能しません。

  //[self.window addSubview:startViewControllerView.view];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

それで、何が足りないのですか? initWithFrame を呼び出す正しい方法は何でしょうか?

どうもありがとう!

4

1 に答える 1

1

すべてのビューコントローラーが自動リリースされるのはなぜですか? おそらくそれらを保持し、使い終わったときにのみ解放する必要があります。

あなたの構造に関しては、タブバーコントローラーの各タブに単一のナビゲーションコントローラーを構築し、それらをコントローラーに追加してから、タブバーコントローラーをウィンドウに追加すると、次のように機能することがわかりました...

AppDelegate.h

property (nonatomic, retain) UITabBarController *tabBarController;
property (nonatomic, retain) UINavigationController *firstNavController;
property (nonatomic, retain) UINavigationController *secondNavController;
property (nonatomic, retain) FirstViewController *firstViewController;
property (nonatomic, retain) SecondViewController *secondViewController;

AppDelegate.m

firstViewController = [[FirstViewController alloc] someInitMethod:someArg];
firstNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 

secondViewController = [[SecondViewController alloc] someInitMethod:someArg];
secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 

tabBarController = [[UITabbarController alloc] init];

NSArray *tabs = [NSArray arrayWithObjects:firstNavController, secondNavController, nil];

[tabBarController setViewControllers:tabs animated:NO];

self.window.rootViewController = tabBarController;
[self.window makeKeyAndVisible];
于 2011-08-20T05:47:55.590 に答える