Swift - disable refreshControl while searching

While searching, I want to disable the pull mechanism for the update. So I turned off update management and uninstalled it. But when pulling down to refresh, the beginRefresh method is called and the cells stay for 2 seconds as there is refresh.

func searchBarShouldBeginEditing(searchBar: UISearchBar) -> Bool {
    resultSearchController.searchBar.selectedScopeButtonIndex = 0
    refreshControl!.enabled = false
    refreshControl?.removeFromSuperview()
    return true
}

      

+3


source to share


2 answers


Use these two functions when you want to create or remove update controls at the top of the 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
}

      

+2


source


When searching then check if there is a refreshControl superView and Remove from superView.After searching End Add it again, the condition will look like this:



if self.refreshControl.isDescendant (of: self.tblView) {self.refreshControl.removeFromSuperview ()}

0


source







All Articles