Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show back button without navigation view controller

Tags:

ios

swift

I have the scheme: UITabBarViewController (with 3 tabs).
In all that tabs I don't want to show navigation menu on top. And from the first tab, I want to push another view controller from button click that will have "back" button (and top toolbar with "cancel")

I tried some ways - in storyboard with push segue - no back button. Probably because i don't have navigation view controller, so my navigation stack is empty.

Programmatically:

let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let nextViewController = storyBoard.instantiateViewController(withIdentifier: "AddCoinTableViewController") as! AddCoinTableViewController
self.present(nextViewController, animated:true, completion:nil)

If I embed tabs in navigation controller, then I have top toolbar (which I don't want).

Any ideas how to make it?

like image 833
Vadim Avatar asked Dec 10 '22 08:12

Vadim


2 Answers

You can't achieve navigation functionality without using UINavigationController. I mean you have to do all animation kind of stuff on your own, and I think that's not a good idea. Rather than that, you can use UINavigationController, and if you don't want to show navigationBar at some viewController, than do as follows for those view controllers.

override func viewWillApear() {
    super.viewDidLoad()
    self.navigationController?.isNavigationBarHidden = true
}

override func viewWillDisappear(animated: Bool) {
    self.navigationController?.isNavigationBarHidden = false
}
like image 130
Sharad Paghadal Avatar answered Dec 29 '22 09:12

Sharad Paghadal


You can embed the navigation controller at your first tab controller (or any you want), and hide it at the controllers you don't want on their viewDidLoad like this:

self.navigationController?.isNavigationBarHidden = true

Doing this, you will be able to see the back Button at the controllers you pushed and didn't hide the navigationBar.

Make sure you push the controller using the navigation controller like this:

self.navigationController?.pushViewController(YOUR VIEW CONTROLLER, animated: true)

like image 43
Gustavo Vollbrecht Avatar answered Dec 29 '22 09:12

Gustavo Vollbrecht