2

for the past one year I have not built an iOS app because I have to concentrate in Android development. and there are a lot of changes in iOS 13 development

I have some VCs in navigation controller like this enter image description here

when I use push segue from VC1 to VC2 and back to VC1, then it will make it like a cards like this. here is the code I use when the button in the first VC is clicked

@IBAction func createEventButtonDidPressed(_ sender: Any) {

    // do some actions first and then
    performSegue(withIdentifier: "chooseEventName", sender: nil)
}

enter image description here

I have tried to read this Presenting modal in iOS 13 fullscreen , so I make fullscreen modal segue like this

enter image description here

but it will make the navigation bar in VC2 (that blue vc) will not show.

I have tried to select to bar to be 'Translucent navigation bar' enter image description here

but when I run the app, I can't get that navigation bar in second VC, the navigation bar doesn't show when using fullscreen modal segue

I really need the behaviour exactly the same before iOS 13. like using push segue and the navigation bar still on top without look like a cards

how to do that ?

sarah
  • 3,819
  • 4
  • 38
  • 80

2 Answers2

1

Let's then refresh your mind in iOS a bit.

PUSH requires navigationController. This makes the new screen slides to the leading side. If there's no navigationController, then the new screen will be presented modally instead. We use POP in code if we want to make the new screen to be popped and user to go back to the previous screen.

PRESENT does not require navigationController. This makes the new screen slide up. We use DISMISS in code if we want to dismiss it. You can add a navigationController to the next screen if you need one.

Now what's new with iOS 13.0 when it comes to presenting screens? By default, the screens will now be presented as cards, not in fullscreen.

Back to your problem:

I really need the behaviour exactly the same before iOS 13. like using push segue and the navigation bar still on top without look like a cards

You will need to use PUSH not PRESENT. Tap on that segue again, and select SHOW (this is the push equivalent in Interface Builder). And also tap on that VC1 and click on Xcode's EDITOR menu, Embed In, and click NavigationController.

Glenn Posadas
  • 12,555
  • 6
  • 54
  • 95
  • like this https://i.stack.imgur.com/bYlnw.png ? it will make the VC1 like a cards if I back from VC 2 to VC1 – sarah Feb 24 '20 at 03:14
  • Yes, just like that. No it won't, and it shouldn't. That happens because like I said in my answer, you **need** to have a `UINavigationController` in your first screen (VC1). So click on that VC1 ---> click on EDITOR located at the top of Xcode ---> Embed In ---> NavigationController. – Glenn Posadas Feb 24 '20 at 03:22
  • in my screenshot above, I have already embedded the VC to navigation controller actually.if I embed it again then I will have 2 navigation controller like this ? https://i.stack.imgur.com/m8SbT.png but unfortunately the cards are still there – sarah Feb 24 '20 at 03:36
  • No need to embed it, my bad, I didn't notice your navigation controller. I thought it's a tab bar controller. This should be not that trivial, a push/show should use a navigationController, and that's it. The cards will only be used for modal / present. How about make a fresh project and try to experiment from there while reading my explanation above? – Glenn Posadas Feb 24 '20 at 03:48
  • yes, when that button in first VC is clicked, after doing some actions, then I use I use performSegue(withIdentifier: "chooseEventName", sender: nil) – sarah Feb 24 '20 at 03:48
  • I have tried to make new project, and your answer is right. the problem is because I use performSegue(withIdentifier: "chooseEventName", sender: nil). if I set push segue in storyboard, then what makes to trigger to move to the next VC ? I assume that I have to use performSegue to triger that move, because I need to perform some actions first before moving to next VC. I have added the code in my question – sarah Feb 24 '20 at 03:59
  • `performSegue` is okay. That's what it is used for, to perform the segue whenever you want. Now I can't see any more reasons why the modal presentation happens (as what you keep on saying) even though you are using "show". Another way to handle screen transitions aside from using segues/performSegue is to use the full codes. https://freakycoder.com/ios-notes-19-how-to-push-and-present-to-viewcontroller-programmatically-how-to-switch-vc-8f8f65b55c7b – Glenn Posadas Feb 24 '20 at 04:14
0

If you embed VC2 into its own Navigation Controller it will display with the navigation bar. So your view should look like UINav->VC1->UINav->VC2

When presenting a view full screen and modal, all previous Navigation Controllers don’t form part of the new stack.

Darren
  • 10,182
  • 20
  • 95
  • 162