2015-10-22 34 views
0

This Pickture is black out screen but build success...的Objective-C的UINavigationController +的UITabBarController

我的應用程序有UINavigationController的和的UITabBarController。 但是,secondViewController在顯示屏上是黑色的!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
//2 UIViewControllerの生成 
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:nil bundle:nil]; 
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:nil bundle:nil]; 
NoteFunction *noteFunction = [[NoteFunction alloc]initWithNibName:nil bundle:nil]; 




//3 UINavigationControllerの生成 
navigationController1 = [[UINavigationController alloc]initWithRootViewController:firstViewController]; 
navigationController3 = [[UINavigationController alloc]initWithRootViewController:noteFunction]; 

//4 NavigationControllerを配列にしてまとめる 
navi = [NSArray arrayWithObjects:navigationController1,navigationController3,nil]; 
//5 tabbarcontrollerの生成 
tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil]; 
[tabBarController setViewControllers:navi animated:NO]; 

self.window.rootViewController = tabBarController; 

noteFunction.title = @"ノート"; 

[window addSubview:tabBarController.view]; 
[self.window makeKeyAndVisible]; 
return YES; 

回答

1

您的需求這段代碼,我會給樣品coding.This是確切的解決方案

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 

    FirstViewController *firstVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
    UINavigationController *firstNavVC = [[UINavigationController alloc] initWithRootViewController: firstVC]; 

    SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
    UINavigationController *secondNavVC = [[UINavigationController alloc] initWithRootViewController: secondVC]; 

    ThirdViewController *thirdVC = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil]; 
    UINavigationController *thirdNavVC = [[UINavigationController alloc] initWithRootViewController: thirdVC]; 

    NSMutableArray *tabViewControllers = [[NSMutableArray alloc] init]; 
    [tabViewControllers addObject:firstNavVC]; 
    [tabViewControllers addObject:secondNavVC]; 
    [tabViewControllers addObject:thirdNavVC]; 

    firstNavVC.tabBarItem = 
    [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"First", nil) 
           image:nil 
           tag:1]; 

    secondNavVC.tabBarItem = 
    [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Second", nil) 
           image:nil 
           tag:2]; 
    thirdNavVC.tabBarItem = 
    [[UITabBarItem alloc] initWithTitle:NSLocalizedString(@"Third", nil) 
           image:nil 
           tag:3]; 

    UITabBarController *tabbarController = [[UITabBarController alloc] init]; 
    tabbarController.viewControllers = tabViewControllers; 

    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 
    self.window.rootViewController = tabbarController; 

    [self.window makeKeyAndVisible]; 
    return YES; 

} 
+0

請投票我的答案。 – user3182143

0

我已經解決了這個節目!

我寫「注意Function.h」

(void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    NSLog(@"Called!ViewDidLoad"); 
    [self.navigationController setNavigationBarHidden:NO animated:YES]; 
    [self.navigationController setToolbarHidden:YES animated:YES]; 
    self.view.backgroundColor = [UIColor whiteColor]; 
    // Do any additional setup after loading the view, typically from a nib.} 
} 
+0

亞思如果我的回答是有幫助你請放棄投票或投票我的答案。它似乎對其他人很有幫助,他們提到你的問題。 – user3182143

+0

即使您嘗試我的答案,我的代碼也能正常工作。 – user3182143

相關問題