Swift - 搜索时禁用 refreshControl [英] Swift - Disable refreshControl while searching

查看:27
本文介绍了Swift - 搜索时禁用 refreshControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在搜索过程中,我想禁用下拉刷新机制.所以我禁用了刷新控件并将其删除.但是当下拉刷新时,beginRefresh 方法被调用,单元格会像刷新一样保持关闭 2 秒.

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
}

推荐答案

搜索时检查refreshControl是否有superView并从superView中移除,搜索完再添加,条件如下:

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() 
  }

这篇关于Swift - 搜索时禁用 refreshControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆