0

Is there a way to show navigation view on one view and not show it on another at the same time?

The problem: I have two view controllers - table and description view (called on cell click).

Table got a navigation bar, while description view - don't have it.

Table view:

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    self.navigationController?.isNavigationBarHidden = false
}

Description view controller:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.isNavigationBarHidden = true
}

Everything works fine, but when i swipe for half screen back to table (keeping finger on screen, watching both views) - i don't see navigation bar (which works as expected with that code), and when i release finger - whole table view jumps, because nav bar is shown.

Is there a way to keep not seeing nav bar in description view and see it all the time in table view?

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Vadim
  • 3,855
  • 2
  • 17
  • 22
  • Possible duplicate of [how to hide navigationbar when i push from navigation controller?](https://stackoverflow.com/questions/1617565/how-to-hide-navigationbar-when-i-push-from-navigation-controller) – Enea Dume May 23 '18 at 16:07

2 Answers2

1
override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    self.navigationController?.setNavigationBarHidden(false, animated: true)
}



override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.navigationController?.setNavigationBarHidden(true, animated: true)
}
Alexey Kudlay
  • 525
  • 2
  • 14
0

You can hide the navigation bar while doing the segue (earlier). If you're doing it programmatically:

yourVCToBePushed.navigationController?.isNavigationBarHidden = true

If you're doing it in the storyboard, do similarly inside prepareForSegue:

let yourVCToBePushed = segue.destination as! YourVCToBePushed (type)
   yourVCToBePushed.navigationController?.isNavigationBarHidden = true

You can also create your own "navigationView" inside tableView header, and add buttons there.

Kowboj
  • 351
  • 2
  • 14