Sobes.tech
Junior — Middle

What are the consequences of opening multiple screens using push and then closing the last one with dismiss?

sobes.tech AI

Answer from AI

When navigating in iOS using UINavigationController, the pushViewController method adds a new screen (ViewController) to the navigation stack. If multiple screens are opened this way, they will be added sequentially to the stack.

If you then try to close the last screen using dismiss, it will not work because dismiss is used to close modally presented controllers, not those in the navigation stack. As a result, the last screen will remain on the screen, and the user will not return to the previous one.

To close screens added via push, you should use the popViewController or popToViewController method. Calling dismiss on a controller that was opened via push will not produce the expected result, as dismiss only works with modal transitions.

Summary:

  • push adds a screen to the navigation stack.
  • dismiss closes modally presented screens.
  • Closing push screens with dismiss does not work; you need to use pop.
What are the consequences of opening multiple screens… - sobes.tech