iOS 13: Searchbar crashing when cancel is hit repeatedly.

I'm getting a crash when users click the cancel button repeatedly:


*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Nested internal _UISearchBar transitions not yet supported. This is an internal UIKit bug.'


Steps:

- Launch a window with the search bar showing.

- Make the search bar text field the first responder. I have the cancel button enabled, so it shows up.

- Tap on the location of the cancel button a few times.

- Watch the app crash.


I've instrumented the delegate, and it looks something like this:

kb: should begin editing
kb: will show
kb: did begin editing
kb: should end editing motion: true
kb: should end editing motion: true
kb: should end editing motion: true
kb: did show
kb: canceled in motion: false
kb: should end editing motion: false
kb: will hide
kb: Did End Editing
kb: should begin editing
kb: did hide
kb: will show
kb: did begin editing
kb: should end editing motion: true
kb: should end editing motion: true
kb: should end editing motion: true


where motion indicates that we received either the keyboard will show or keyboard will hide notification without a did show or did hide response.


Any ideas for a workaround?

Replies

I got the same crash too. 😟

Same here

find below fix for this issue.


var isSeachBarAnimationCompleted: Bool = false


func didPresentSearchController(_ searchController: UISearchController) {

DispatchQueue.main.async(execute: {

self.isSeachBarAnimationCompleted = true

searchController.searchBar.becomeFirstResponder()

})

}


func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {

guard self.isSeachBarAnimationCompleted else { return }

self.isSeachBarAnimationCompleted = false

//Do you code here...

}



Hope this will resolve the issue. 🙂

Same problem here ! Any information about when this bug will be fixed in UIKit ?