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

# searchBarCancelButtonClicked(_:)

Tells the delegate that the cancel button was tapped.

```
optional func searchBarCancelButtonClicked(_ searchBar: UISearchBar)
```

## Parameters

`searchBar`

The search bar that was tapped.

## Discussion

Typically, you implement this method to dismiss the search bar.

## See Also

[`showsCancelButton`](/documentation/UIKit/UISearchBar/showsCancelButton)

A Boolean value indicating whether the cancel button is displayed.



---

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)