Swift-搜索时禁用refreshControl

Sve*_*rer 7 uitableview uirefreshcontrol swift

在搜索过程中,我想禁用“刷新”机制。因此,我禁用了刷新控件并将其删除。但是,当下拉刷新时,将调用beginRefresh方法,并且像刷新一样,单元格将保持关闭状态2秒钟。

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

小智 5

如果要在 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
}
Run Code Online (Sandbox Code Playgroud)


小智 5

搜索时,请检查refreshControl是否具有superView并从superView中删除从搜索结束后再次添加它,条件将如下所示:

  if self.refreshControl.isDescendant(of: self.tblView) {
      self.refreshControl.removeFromSuperview() 
  }
Run Code Online (Sandbox Code Playgroud)