-2

I am new in iOS development and in Swift. I have a question. I added in one of the ViewController NavigationController. But I have some problems with back button cause it doesn't appear on other Views. I tried with self.pushViewController() and with self.present() but it doesn't work. If I mark in NavigationController Is Initial View Controller then everything is fine but I don't want it because then app starts with this screen(where I have NavigationController).

Please help me, what I should to add or to write?

This is an image of my storyboard This is an image of my storyboard

And this is what I have if I run and go to another ViewController, as you can see I don't have navigation bar and back button. enter image description here

Lado
  • 276
  • 2
  • 17
  • You should embed your navigation controller to the first viewcontroller and hide the navigation bar then show it for the rest. check this answer: https://stackoverflow.com/a/29209623/4569257 – Omar Chaabouni Apr 04 '19 at 15:17
  • @OmarChaabouni I override only viewWillAppear() to the first viewcontroller should I add there viewWillDisapper() or I add this function in the second one(i override viewWillDisappear only in the second viewcontroller)? – Lado Apr 04 '19 at 15:25
  • Both work but I would do it in the viewWillDisappear – Omar Chaabouni Apr 04 '19 at 15:30
  • "If I mark in NavigationController Is Initial View Controller then everything is fine but I don't want it because then app starts with this screen(where I have NavigationController)" But that is excellent! Explain how you get beyond the initial screen that the app starts with. – matt Apr 04 '19 at 15:37
  • @OmarChaabouni I did it but still same, nothing happened. By the way, I deleted this part and in general, it must me show navigation bar(i mean in the first viewcontroller) but I didn't get it – Lado Apr 04 '19 at 15:42
  • @matt if I understand you correctly, now I have another one screen where I can log out from app – Lado Apr 04 '19 at 15:45
  • @Lado did you embed your initial viewcontroller with a navigation controller? – Omar Chaabouni Apr 04 '19 at 15:54

1 Answers1

1

You got 2 options :

1) Add a navigation controller in the root ViewController, Hide throughout except the last one. Make sure you push the last VC so Back option will be there by default

self.navigationController.pushToViewController(BarCodeViewController)

2) Use a custom View on top of last viewController add a custom button to that view. But this time present it from previous ViewController

self.present(BarCodeViewController)

when back button clicked dismiss it by adding target to the button. self.dismiss()

Digs
  • 193
  • 1
  • 11