Cancel Button in UISearchController

别等时光非礼了梦想. 提交于 2019-11-29 05:35:27
Gargoyle

You need to set the UISearchController searchBar's delegate. Once you have done this, the addition of the delegate method searchBarCancelButtonClicked: will properly be called.

self.searchController.searchBar.delegate = self;

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
}
samwize

If you implement UISearchResultsUpdating protocol, you can know that cancelled is triggered when active is false.

func updateSearchResultsForSearchController(searchController: UISearchController) {
    if !searchController.isActive {
        print("Cancelled")
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!