During the search I want to disable the pull to refresh mechanism. So I disabled the refresh control and removed it. But when pull down to refresh the beginRefresh method is called and the cells keep being down for 2 seconds like there is a refresh.
func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
resultSearchController.searchBar.selectedScopeButtonIndex = 0
refreshControl!.enabled = false
refreshControl?.removeFromSuperview()
return true
}
Use these two functions if you want to create or delete refresh controls in the top of UITableView.
func createRefreshControl() {
// Create RefreshControl and add to tableView
self.refreshControl = UIRefreshControl()
self.refreshControl!.attributedTitle = NSAttributedString(string: " ↓ Refresh ↓ ")
self.refreshControl!.addTarget(self, action: "refresh:", forControlEvents: UIControlEvents.ValueChanged)
}
func deleteRefreshControl() {
// delete RefreshControl
self.refreshControl = nil
}
When search then check if refreshControl has superView and Remove from superView After search End Add it again, the condition will look like :
if self.refreshControl.isDescendant(of: self.tblView) {
self.refreshControl.removeFromSuperview()
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With