---
title: "popToViewController(_:animated:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uinavigationcontroller/poptoviewcontroller(_:animated:)"
---

# popToViewController(_:animated:)

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

## Declaration

```swift
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

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

## Discussion

Discussion For information on how the navigation bar is updated, see Updating the navigation bar.

## See Also

### Pushing and popping stack items

- [pushViewController(_:animated:)](uikit/uinavigationcontroller/pushviewcontroller(_:animated:).md)
- [popViewController(animated:)](uikit/uinavigationcontroller/popviewcontroller(animated:).md)
- [popToRootViewController(animated:)](uikit/uinavigationcontroller/poptorootviewcontroller(animated:).md)
- [interactivePopGestureRecognizer](uikit/uinavigationcontroller/interactivepopgesturerecognizer.md)
- [interactiveContentPopGestureRecognizer](uikit/uinavigationcontroller/interactivecontentpopgesturerecognizer.md)
