Reputation: 3195
My app starts with a view with some buttons. I want to navigate to different views depending on the button pressed and pass them different parameters.
My storyboard looks as follows:
.
As you can see, pressing a button in the main view calls a table view embedded in a navigation controller. And this is causing to me a lot of problems!
At first I don't know if I've chosen the right approach, or if I've to start my app with a navigation controller instead of a view (I've tried this solution, but in my home page I don't want a navigation bar, and also making it visible or not, isn't really nice visually).
In case you confirm the feasibility of my initial approach, how can I navigate to the desired view also passing some parameters?
------Edit:
I finally found a working solution. The Navigation controller is the first controller in my application. Views are connected with standard segue.
In my home view:
- (void)viewWillAppear:(BOOL)animated
{
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
In my table view:
- (void)viewWillAppear:(BOOL)animated
{
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
In this way, when you push the button, the new view is displayed with an animation, that is the same of the navigation bar. And the same happens when you press the back button in the table view.
No more lines of code are needed!!!
The only addiction you can do to make it perfect, is to manage the first time the app is loaded to hide the navigation bar in the home view without animation.
yassa
Upvotes: 0
Views: 2337
Reputation: 1265
in a very similar case, I put the navigation controller as a initial controller in the storyboards so that the home page would be a root view controller for this navigation controller.
So the view controllers stack would look like this:
Storyboards - HomeViewController - YourTableViewController
If you want to hide the navigation bar in the home page you just need to hide/show it from the code using:
[self.navigationController setNavigationBarHidden:YES animated:NO];
and when you want to show it in the view controller use :
[self.navigationController setNavigationBarHidden:NO animated:NO];
These lines of code should go to methods connected with displaying the view, i.e. viewDidAppear: or to the prepareForSegue: method
EDIT: I also added in my app some delay in pushing the next view controller:
[self.navigationController setNavigationBarHidden:NO animated:YES];
// Showing navigation bar animation
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.2 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[self.navigationController pushViewController:viewController animated:YES];
});
Upvotes: 1