2014-09-24 102 views
1

我是iOS新手,在Xcode 6更新後,我在taBbar中顯示導航控制器時出現問題。結合TabBar和導航控制器IOS8

在Xcode 5,它是完美的,但現在工作在模擬器上我得到一個錯誤信息「終止應用程序由於未捕獲的異常‘NSInvalidArgumentException’,原因:‘推導航控制器,不支持’」和應用程序崩潰。 這裏是我的代碼:

**appDelegate.m** 

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

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
self.window.backgroundColor =[UIColor whiteColor]; 
[self.window makeKeyAndVisible]; 

*// tabBar items* 

ItemUnViewController *itemUnViewController = [[ItemUnViewController alloc] 
                  initWithNibName:nil 
                  bundle:NULL]; 


ItemDeuxViewController *itemDeuxViewController = [[ItemDeuxViewController alloc] 
                   initWithNibName:nil 
                   bundle:NULL]; 

*//tabBar* 

UITabBarController *tabBarController = [[UITabBarController alloc] init]; 

[tabBarController setViewControllers:@[itemUnViewController,itemDeuxViewController]]; 


*//setting tabBar as rootView* 

self.window.rootViewController = tabBarController; 


*// navigation Controllers* 

UINavigationController *itemUnNavigationController = 
[[UINavigationController alloc] 
initWithRootViewController:itemUnViewController]; 

UINavigationController *itemDeuxNavigationController = 
[[UINavigationController alloc] 
initWithRootViewController:itemDeuxViewController]; 


*//Combining tabBar and Navigation Controllers* 

[tabBarController setViewControllers:@   
[itemUnNavigationController,itemDeuxNavigationController]]; 

return YES; 
} 

我甚至試過這種方式http://blog.rifkilabs.net/exploring-navigation-controller-and-tab-bar-controller.html,但我得到了同樣的錯誤消息。

感謝您的幫助。

回答

0
  tabBar_Controller = [[UITabBarController alloc]init]; 
       [tabBar_Controller setDelegate:self]; 



      ViewController1 *obj_1 = [obj_story instantiateViewControllerWithIdentifier:@"VC1"]; 
      UINavigationController *navi_vc1 = [[UINavigationController alloc]initWithRootViewController:obj_1]; 
      navi_vc1.navigationBarHidden = YES; 

     ViewController2 *obj_2 = [obj_story instantiateViewControllerWithIdentifier:@"VC2"]; 
      UINavigationController *navi_vc2 = [[UINavigationController alloc]initWithRootViewController:obj_2]; 
      navi_vc2.navigationBarHidden = YES; 


     [tabBar_Controller setViewControllers:[NSArray arrayWithObjects:navi_vc1,navi_vc2,nil]]; 

    //Hide Tabbar View Controller.// 
     [self hideTabBar] 
    =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
    -(void) hideTabBar 
    { 
     for(UIView *view in tabBar_Controller.view.subviews) 
     { 
      if([view isKindOfClass:[UITabBar class]]) 
      { 
       [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width, view.frame.size.height)]; 
      } 
      else 
      { 
       [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)]; 
      } 
     } 
    } 
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- 
-(void)create_BottomBarButton 
{ 
    UIView *viewBottom = (UIView *)[self.window viewWithTag:Tag_BottomView]; 

    if (viewBottom == nil) 
    { 
     @try 
     { 
      viewBottom = [[UIView alloc]init]; 
      [viewBottom setFrame:CGRectMake([UIScreen mainScreen].bounds.origin.x, [UIScreen mainScreen].bounds.size.height-(HeightOfBottomBar+KsubviewHeight), [UIScreen mainScreen].bounds.size.width, HeightOfBottomBar)]; 
      [viewBottom setBackgroundColor:RGB(47.0, 45.0, 45.0, 1.0)]; 
      [viewBottom setTag:Tag_BottomView]; 
      NSArray *arrImage = [NSLocalizedString(@"arrBottomBarImgs", nil)componentsSeparatedByString:@","]; 
      float x = 0.0; 
      for (int i =0; i < kTotalTab; i++) { 
       [self create_TabBtn:viewBottom frame:CGRectMake(x, 0, 62,62) withTag:i+1 withImage:[arrImage objectAtIndex:i]]; 
       x += 64.5; 
      } 
      [self.window addSubview:viewBottom]; 
     } 
     @catch (NSException *exception) 
     { 
      NSLog(@"EXCEPTON %@",[exception description]); 
     } 
    } 
} 
-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=- 
-(void)select_Tab:(UIButton *)btn 
{ 
    @try { 
     [[tabBar_Controller.viewControllers objectAtIndex:btn.tag-1] popToRootViewControllerAnimated:YES]; 
     [tabBar_Controller setSelectedIndex:btn.tag-1]; 
    } 
    @catch (NSException *exception) { 
     NSLog(@"%s",__PRETTY_FUNCTION__); 
    } 
} 

- = - = - = - = - = - = - = - = - = - = - = - = - = -

-(void)pushTabBarIntoNavigationBar 
{ 
    [navi setNavigationBarHidden:YES]; 
    [[UIApplication sharedApplication] setStatusBarHidden:NO]; 
    [navi pushViewController:tabBar_Controller animated:YES]; 
} 

- = - = - = - = - = - = - = - = - = - = - =

navi = [[UINavigationController alloc]initWithRootViewController:tabBar_Controller]; 
[navi setNavigationBarHidden:YES]; 
    self.window.rootViewController = navi;