Reputation: 1404
I have several ViewController chained together with segue in a simple hierarchy.
In each of them :
[self performSegueWithIdentifier:@"myController" sender:myVar];
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"myController"]){
MyController *controller = (MyController *)segue.destinationViewController;
controller.myVar = sender;
}
}
I'm looking for the simplest way to integrate a top navigation bar with a back button. I know I can use something like this in viewWillAppear
:
UINavigationBar *myNav = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, x, y)];
[self.view addSubview:myNav];
But in this case the navigation bar hides a part of the view (like a "position:absolute" would in css).
I can add a Navigation Controller which solves the problem above but from what I understand this will make my segue useless, which I don't want.
Upvotes: 0
Views: 974
Reputation: 17576
This is exactly what UINavigationController
is for. Your first view controller (called the root) is embedded in a navigation controller. Additional view controllers are then pushed onto the navigation controller.
UINavigationController automatically manages the navigation bar on the top and creates the back button for you.
Once you have embedded your view controller in a navigation controller, you can use push segues.
Upvotes: 2