Search code examples
uiviewuiviewcontrolleruikituisearchcontrolleruiview-hierarchy

UISearchController extra unexpected UIView in hierarchy


I have problem with UISearchController. It is adding one extra View as direct child of its View. It has isAccessibilityElement = true and description "Double-tap to dismiss", this blocks all Appium automatic testing. I can't figure out why, where and how it is added.

Someone know when and why this view is added and how to remove it? I have tried to set its isAccessibilityElement = false form code but somehow it is set back to true in some cases.


Solution

  • For anyone else who has this issue. It's caused by the default behaviour Apple have given the UISearchController where the searchResultsController is initially hidden until the UISearchBar has text.

    We had old code in the searchResultsController to unhide itself view.isHidden = false which fought this default logic.

    The fix was to remove this and instead set searchController.showsSearchResultsController = true which shows the results always and doesn't add the double tap to dismiss view.