UISearchController searchBar showsCancelButton not being respected

后端 未结 12 2358
北荒
北荒 2021-02-13 03:58

I\'ve added a UISearchController to my application and set it\'s searchBar to the titleView of my navigationItem.

This works but I am seeing t

12条回答
  •  猫巷女王i
    2021-02-13 04:12

    I agree, it seems like a bug. The problem is that the searchController keeps resetting the showsCancelButton property of the searchBar. I found a solution that involves:

    1. subclassing UISearchBar to ignore setShowsCancelButton.
    2. to make the searchController use that subclass, you have to subclass UISearchController.
    3. And then you find that the searchBar is not triggering the search controller's delegate methods, so you have to trigger them separately...

    Convoluted, but it seems to do the trick. You can find the full answer here.

提交回复
热议问题