Cancel Button in UISearchController

后端 未结 3 775
名媛妹妹
名媛妹妹 2020-12-17 09:32

In my project I\'m using a UITableViewController with an internal UISearchController to filter the data in my tableView.

I ha

相关标签:
3条回答
  • 2020-12-17 10:23

    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")
        }
    }
    
    0 讨论(0)
  • 2020-12-17 10:26

    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 {
    }
    
    0 讨论(0)
  • 2020-12-17 10:26

    Swift 5

    searchBar.delegate = self
    .......
    
    extension YourClass: UISearchBarDelegate {
        func searchBarCancelButtonClicked(_ searchBar: UISearchBar){} 
    }
    
    0 讨论(0)
提交回复
热议问题