Search code examples
swiftbuttonviewcontrollerback

Why Are Back Buttons Missing & Views Being Presented Modally Despite Being Embedded In A Navigation Controller?


After my app grew I had to change my "initial view controller" or what I understand to be the "entry point" view. So I deleted my original my original navigation controller & embedded a newly created view into a new navigation controller. I unchecked the view that was initially the "Initial View Controller" & selected "initial View Controller" of the newly created replacement view. My issue despite is despite showing on the storyboard as being embedded in the new Navigation controller upon loading the simulator there is a Gap at the top of my views & although a back button is showing on storyboard) there is no visible back button in simulator. Views are being presented in a way that I understand to be "modally" (from bottom to top) & can be removed by swiping downwards.

enter image description here

What I am trying to Accomplish is behaviour like when a view is embedded in a View Controller with the back buttons present & entering from right to left (but I have embedded my initial view controller but behaviour persists)

I have made sure to (when creating segues to select "show") & when I deleted the NEW view controller after experiencing the behaviour described & re-added the back buttons where visible temporarily but after closing & relaunching it was back to modally.

Im certain there is lots I have failed to explain but I m hoping this will sound familiar to someone & I will answer any questions Ive neglected to explain. Still very new to Swift & any help is sincerely appreciated. Thank You.

enter image description here


Solution

  • You seem to have your storyboard entry point set to the initial view controller, instead of the navigation controller. This makes the navigation controller pretty much useless, which is why things are still being presented modally. There is a small arrow in your second picture pointing to your initial view controller (the screen with the "sign up" and "log in" buttons). It looks like this:

    enter image description here

    This is the storyboard entry point. It should be on the navigation controller instead of the initial view controller. You can do one of the following to fix the problem:

    Drag and drop the arrow to the left of the navigation controller.

    OR

    Select the navigation controller, and in the attributes inspector, check "Is Initial View Controller".

    Build and run and you should be good to go.

    I saw what you said about how in the storyboard it shows the back buttons, and here's why I think that is so, but not in the simulator: Xcode Storyboard probably thinks that since the view is embedded in the navigation controller, the navigation controller will be loaded, so it is showing what would happen if the navigation controller was actually loaded. But since the storyboard entry point skips right over the navigation controller, the navigation controller is never loaded during the run.