<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UINavigationController/popToViewController(_:animated:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UINavigationController(im)popToViewController:animated:"
  },
  "title" : "popToViewController(_:animated:)"
}
-->

# popToViewController(_:animated:)

Pops view controllers until the specified view controller is at the top of the navigation stack.

```
func popToViewController(_ viewController: UIViewController, animated: Bool) -> [UIViewController]?
```

## Parameters

`viewController`

The view controller that you want to be at the top of the stack. This view controller must currently be on the navigation stack.

`animated`

Set this value to <doc://com.apple.documentation/documentation/Swift/true> to animate the transition. Pass <doc://com.apple.documentation/documentation/Swift/false> if you are setting up a navigation controller before its view is displayed.

## Return Value

An array containing the view controllers that were popped from the stack.

## Discussion

For information on how the navigation bar is updated, see [`Updating the navigation bar`](/documentation/UIKit/UINavigationController#Updating-the-navigation-bar).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)