2014-09-24 132 views
0

我正在研究一个iOS应用程序。 我的问题是,在我的故事板上,我有一个导航栏显示,但是当我运行该应用程序,它隐藏,我不知道为什么......为什么我的UINavigationbar被隐藏?

首先我有一个“StartViewController”并显示MainViewController,我这样做是:

- (void)finishDownloadDataWithError:(NSError *)error{ 
//si il ya pas eu d'erreur on arrête la video et on éxecute loadMainView. 
if (error == nil) { 
    NSLog(@"download OK"); 

    //simule un téléchargeemnt de 3s 
    //[NSThread sleepForTimeInterval:2.f]; 
    _loadingIndicator.hidden = YES; 


} 
//si il ya eu des erreur on affiche la popup d'erreur. 
else { 
    NSLog(@"download fail"); 


} 
//on utilise ce booléen pour être sur de ne créer qu'une seul fois les instances des controllers 
static BOOL firstTime = YES; 
if (firstTime) { 
    firstTime = NO; 

    //chargement de la vue suivante 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; 
    MainViewController * controller = (MainViewController *)[storyboard instantiateViewControllerWithIdentifier:@"MainViewController"]; 
    [self presentViewController:controller animated:YES completion:nil]; 

    } 

} 

这里是我的MainViewController

- (void)viewWillAppear:(BOOL)animated{ 


self.navigationBar.title = @"FoodStash"; 
self.navigationController.navigationBar.barTintColor = [UIColor redColor]; 
self.navigationController.navigationBar.translucent = NO; 
self.navigationController.navigationBar.tintColor = [UIColor blueColor]; 
[self.navigationController setNavigationBarHidden:NO animated:NO]; 

}

这里是我的故事板: enter image description here

here the simulator without my navigationbar !!!!

这里是没有我的导航栏模拟器!!!! 你能帮我吗?

UPDATE 我尝试这一点,但我mainviewController现在不出现。

//chargement de la vue suivante 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; 
    UINavigationController *naviCon = [storyboard instantiateViewControllerWithIdentifier:@"NavigationController"]; 
    [self presentViewController:naviCon animated:YES completion:nil]; 
+0

检查'self.n avigationController'为零。 – KudoCC 2014-09-24 07:56:21

+0

他是零...初始化它的最好方法是什么?和哪里?在我的startviewcontroller? – Jeffrey 2014-09-24 08:26:25

回答

0

您需要为故事板中的navigationController提供故事板ID,即“navigationController”,并且您需要在下面添加行。

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
UINavigationController *naviCon = [storyboard instantiateViewControllerWithIdentifier:@"NAVIGATION_CON_ID"]; 
// [naviCon addChildViewController:YOUR_VIEW_CON_OBJ]; //no need of this lines as your navigation controller is connected with your VC so it will automatically show your VC. 
[self presentViewController:naviCon animated:YES completion:nil]; 

所以现在你可以从故事板和导航栏访问navigationController。

+0

我这样做,但导航控制器没有加载,应用程序停留在starviewController上。 – Jeffrey 2014-09-24 08:11:46

+0

您是否调试过,以检查您是否达到从明星VC跳转到navigationCon的行代码 – nikhil84 2014-09-24 08:16:36

+0

是它到达线路,但没有出现 – Jeffrey 2014-09-24 08:28:15

0

既然你显示你MainViewController有:

[self presentViewController:controller animated:YES completion:nil]; 

这是一个全屏视图显示一个模式,而不是按一个SEGUE,也许你应该考虑嵌入你的第一个视图导航控制器,并使用推塞格斯。

[self.navigationController pushViewController:controller animated:Yes]; 
1

我得到了你的问题。

请检查导航控制器是初始视图控制器

enter image description here

后您ViewController设定为RootViewController如下面的截图

这是你的结果:

enter image description here
enter image description here

,并为HomeView控制器 “HomeID” 一个标识符

当u导航:

-(void)MOve_screen 
{ 
    HomeViewController *home = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"HomeID"]; 
    [self.navigationController pushViewController:home animated:YES]; 

} 

如果有任何疑问U可以降至问我:)

+0

它几乎工作,导航栏显示在startviewcontroller。但导航栏没有显示在主视图控制器 – Jeffrey 2014-09-24 08:55:26

+0

雅看到我的应用程序完全显示在所有视图控制器 – 2014-09-24 08:56:17

+0

现在它工作良好;) 只需要隐藏导航栏,当启动视图加载,并显示它之前显示主视图。 – Jeffrey 2014-09-24 09:06:11

0

这里就是我如何解决我的问题。

enter image description here

在startviewcontroller

downloadingdata后:

- (void)finishDownloadDataWithError:(NSError *)error{ 
      [NSThread sleepForTimeInterval:3.f]; 
      //si il ya pas eu d'erreur on arrête la video et on éxecute loadMainView. 
      if (error == nil) { 
       NSLog(@"download OK"); 

       //simule un téléchargeemnt de 3s 

       _loadingIndicator.hidden = YES; 


      } 
      //si il ya eu des erreur on affiche la popup d'erreur. 
      else { 
       NSLog(@"download fail"); 


      } 
      //on utilise ce booléen pour être sur de ne créer qu'une seul fois les instances des controllers 
      static BOOL firstTime = YES; 
      if (firstTime) { 
       firstTime = NO; 


       self.navigationController.navigationBar.hidden = NO; 

       MainViewController *home = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"]; 
       [self.navigationController pushViewController:home animated:YES]; 

      } 

     } 

在startviewcontroller再次:

- (void)viewWillAppear:(BOOL)animated{ 
     self.navigationController.navigationBar.hidden = YES; 
    } 

在我mainViewController:

 - (void)viewWillAppear:(BOOL)animated{ 

      self.navigationItem.hidesBackButton = YES; 
      self.title = @"FoodStash"; 

      } 
相关问题