---
title: "targetViewController(forAction:sender:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uiviewcontroller/targetviewcontroller(foraction:sender:)"
---

# targetViewController(forAction:sender:)

Returns the view controller that responds to the action.

## Declaration

```swift
func targetViewController(forAction action: Selector, sender: Any?) -> UIViewController?
```

## Parameters

- `action`: The requested action.
- `sender`: The object sending the request.

## Return Value

Return Value The view controller that handles the specified action or nil if no view controller handles the action.

## Discussion

Discussion This method returns the current view controller if that view controller overrides the method indicated by the action parameter. If the current view controller does not override that method, UIKit walks up the view hierarchy and returns the first view controller that does override it. If no view controller handles the action, this method returns nil. A view controller can selectively respond to an action by returning an appropriate value from its canPerformAction(_:withSender:) method.

## See Also

### Adding a custom transition or presentation

- [transitioningDelegate](uikit/uiviewcontroller/transitioningdelegate.md)
- [transitionCoordinator](uikit/uiviewcontroller/transitioncoordinator.md)
- [presentationController](uikit/uiviewcontroller/presentationcontroller.md)
- [popoverPresentationController](uikit/uiviewcontroller/popoverpresentationcontroller.md)
- [sheetPresentationController](uikit/uiviewcontroller/sheetpresentationcontroller.md)
- [activePresentationController](uikit/uiviewcontroller/activepresentationcontroller.md)
- [restoresFocusAfterTransition](uikit/uiviewcontroller/restoresfocusaftertransition.md)
- [Customizing and resizing sheets in UIKit](uikit/customizing-and-resizing-sheets-in-uikit.md)
