I hope to switch between 2 UIViewController using UINavigationController. (AUIViewController, BUIViewController relate to UIView AView,BView)
AView has an UIButton, BView has an UIButton also. If I press the button on AView, it will push BViewController and display BView. If I press the button on BView, BViewController will pop and go back AUIViewController.
I hope to use UINavigationController's navigation function but hide its 'go back' bar and navigation bar, only use 2 buttons to tell UINaviationController what it needs to do. Is it possible?
Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.
To hide the navigation bar in Swift, you'll need to add code to two methods: viewWillAppear and viewWillDisappear . That's it to hide the navigation bar in your view controller.
to hide UINavigationController's navigation bar:
[self.navigationController setNavigationBarHidden:YES];
To push a view controller from a button:
- (void)pushNextViewController {
NextViewController *page = [[NextViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:page animated:YES];
}
To pop a view controller back one:
- (void)popToLastViewController {
[self.navigationController popViewControllerAnimated:YES];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With