Bird
0
0

You want to programmatically navigate back to the root view controller from a deep screen. Which code snippet correctly achieves this?

hard📝 navigation Q15 of 15
iOS Swift - Navigation
You want to programmatically navigate back to the root view controller from a deep screen. Which code snippet correctly achieves this?
AnavigationController?.popToRootViewController(animated: true)
BnavigationController?.popViewController(animated: true)
CnavigationController?.dismiss(animated: true)
DnavigationController?.pushViewController(rootViewController, animated: true)
Step-by-Step Solution
Solution:
  1. Step 1: Understand navigation stack methods

    popToRootViewController moves back to the first screen in the stack, popping all intermediate ones.
  2. Step 2: Compare options

    popViewController removes only the top screen; dismiss is for modal; push adds a new screen, not back.
  3. Final Answer:

    navigationController?.popToRootViewController(animated: true) -> Option A
  4. Quick Check:

    popToRootViewController = go back to root [OK]
Quick Trick: Use popToRootViewController to return to first screen [OK]
Common Mistakes:
  • Using popViewController to go back multiple screens
  • Confusing dismiss with navigation pop
  • Trying to push root instead of popping to it

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes