2011-08-20 30 views
0

林實現組合選項卡欄和導航編程,使用apple documentationiphone組合的選項卡欄和navigationController

調用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的正確方法?

非常感謝!

回答

1

爲什麼你所有的viewcontrollers自動發佈?你應該保留它們,並且只有在你完成它們之後才能釋放它們。

至於你的結構,我發現,建立在tabbarcontroller每個選項卡的單一導航控制器,將那些到控制器,然後添加tabbarcontroller到窗口工作原理是這樣......

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]; 
+0

將autoreleased viewController作爲文檔示例進行管理;我需要解決的是[tabBarController setViewControllers:tabs animated:NO];這不是在文檔!,謝謝! – MaKo