为什么我的UINavigationbar被隐藏了?

时间:2014-09-24 07:54:01

标签: ios xcode uinavigationcontroller ios8 xcode-storyboard

我正在开发一款ios应用。 我的问题是,在我的故事板上,我有一个显示的导航栏,但是当我运行应用程序时,它被隐藏,我不知道为什么......

首先我有一个“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 !!!!

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

更新 我试试这个,但我的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];

4 个答案:

答案 0 :(得分:1)

我遇到了你的问题。

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

enter image description here

之后,您的ViewController设置为RootViewController,如下面的屏幕截图

这是你的结果:

enter image description here
  enter image description here

并为HomeView控制器“HomeID”设置标识符

当你导航时:

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

 }

如果有任何疑问你可以随意问我:)

答案 1 :(得分:0)

您需要在故事板中为navigationController提供storyboard 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。

答案 2 :(得分:0)

由于您向MainViewController显示:

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

这是一个全屏显示的视图,显示的是模态,而不是推送一个segue,也许你应该考虑在导航控制器中嵌入你的第一个视图并使用push segues。

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

答案 3 :(得分:0)

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

enter image description here

下载数据后,在startviewcontroller中

    - (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";

           }
相关问题