Bird
0
0

What will be the result of this code?

medium📝 Predict Output Q5 of 15
iOS Swift - Navigation
What will be the result of this code?
func goBack() {
  navigationController?.popViewController(animated: true)
}
AThe app navigates back to the previous screen with animation
BThe app pushes a new view controller on the stack
CNothing happens because popViewController is incorrect
DThe app crashes due to missing view controller
Step-by-Step Solution
Solution:
  1. Step 1: Understand popViewController method

    This method removes the top view controller and shows the previous one.
  2. Step 2: Animated parameter effect

    Animation is enabled, so the transition will be smooth.
  3. Final Answer:

    The app navigates back to the previous screen with animation -> Option A
  4. Quick Check:

    popViewController = go back one screen [OK]
Quick Trick: popViewController navigates back to previous screen [OK]
Common Mistakes:
  • Confusing pop with push
  • Thinking popViewController adds a screen
  • Assuming popViewController requires storyboard

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More iOS Swift Quizzes