UISearchBar’s delegate method searchBarCancelButtonClicked is not called on search cancel when search bar is integrated into the navigation bar on iOS 27

Hi, I would like to share an issue with UISearchBar's delegate method searchBarCancelButtonClicked on iOS 27 beta.

On iOS 27 beta, when search bar is integrated into navigation bar’s items, tapping search cancel button doesn’t invoke UISearchBar’s delegate method searchBarCancelButtonClicked:.

Steps to reproduce:

  1. Create UINavigationController with one UIViewController
  2. Set up searchController. Set searchController.searchBar.delegate, preferredSearchBarPlacement = .integratedButton, searchBarPlacementAllowsToolbarIntegration = false
  3. Tap the search button and type a query
  4. Tap the search cancel button

Expected: On iOS 26, the searchBarCancelButtonClicked delegate method is called.

Actual: On iOS 27 beta, the searchBarCancelButtonClicked delegate method is NOT called.

On iOS 27 beta, if search bar is “stacked” or placed in the toolbar rather than the navigation bar, the bug does not reproduce.

I’m using Xcode Version 27.0 beta 6 with latest available iOS 27 iPhone 17 Pro simulator (24A5423a).

I reported the issue via Feedback Assistant with a minimal reproduction example and 2 videos comparing the behavior between iOS 26 and iOS 27 beta. Here is the report ID: FB24636315.

Here is the minimal reproduction example:

// SceneDelegate.swift
import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

  var window: UIWindow?

  func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = scene as? UIWindowScene else { return }
    let window = UIWindow(windowScene: windowScene)
    window.rootViewController = UINavigationController(rootViewController: ViewController())
    window.makeKeyAndVisible()
    self.window = window
  }
}

// ViewController.swift
import UIKit

final class ViewController: UITableViewController {

  private let allItems = (1...30).map { "Item \($0)" }
  private var items: [String] = []
  private var cancelCount = 0

  override func viewDidLoad() {
    super.viewDidLoad()
    items = allItems
    updateTitle()

    let searchController = UISearchController(searchResultsController: nil)
    searchController.searchBar.delegate = self

    navigationItem.searchController = searchController
    navigationItem.preferredSearchBarPlacement = .integratedButton
    navigationItem.searchBarPlacementAllowsToolbarIntegration = false

    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
  }

  private func updateTitle() {
    title = "Cancel presses: \(cancelCount)"
  }

  override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    items.count
  }

  override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
    cell.contentConfiguration = {
      var config = cell.defaultContentConfiguration()
      config.text = items[indexPath.row]
      return config
    }()
    return cell
  }
}

extension ViewController: UISearchBarDelegate {

  func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
    print("searchBarCancelButtonClicked(_:)")
    cancelCount += 1
    updateTitle()
    items = allItems
    tableView.reloadData()
  }
}

Thank you in advance!

UISearchBar’s delegate method searchBarCancelButtonClicked is not called on search cancel when search bar is integrated into the navigation bar on iOS 27
 
 
Q