Reputation: 472
I'm working on an ios app. My problem is that on my storyboard I have a navigationbar that is shown, but when I run the application, it is hidden and i dont know why....
First I have a "StartViewController" that loads the data and shows the MainViewController, I do it like that :
- (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];
}
}
Here is my 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];
}
Here is my storyboard :
Here is the simulator without my navigationbar !!!! Can you help me please ?
UPDATE i try this, but my mainviewController dont appear now.
//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];
Upvotes: 0
Views: 402
Reputation: 472
here's how I solved my problem.
in startviewcontroller after 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];
}
}
in startviewcontroller again :
- (void)viewWillAppear:(BOOL)animated{
self.navigationController.navigationBar.hidden = YES;
}
in my mainViewController :
- (void)viewWillAppear:(BOOL)animated{
self.navigationItem.hidesBackButton = YES;
self.title = @"FoodStash";
}
Upvotes: 0
Reputation: 4843
I got your issue.
Please check Navigation Controller as is initial view controller
After that your ViewController
set as RootViewController
like below screenshots
This is your result:
And set a identifier for HomeView controller "HomeID"
when u navigate:
-(void)MOve_screen
{
HomeViewController *home = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"HomeID"];
[self.navigationController pushViewController:home animated:YES];
}
If any doubt u can fell free to ask me :)
Upvotes: 1
Reputation: 954
Since you show your MainViewController
with:
[self presentViewController:controller animated:YES completion:nil];
It's a fullScreen view showed with a modal and not a push a segue, maybe you should consider embedding your first view in a navigation controller and use push segues.
[self.navigationController pushViewController:controller animated:Yes];
Upvotes: 0
Reputation: 3207
You need to provide storyboard id to your navigationController in your storyboard, namely "navigationController" and you need to add below lines.
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];
So now you would have access to your navigationController from storyboard and also your navigation bar.
Upvotes: 0