刷新控件在下拉时在隐藏导航项时在表视图上方留下大间隙



发生这种情况是因为当ios版本超过11时,下面的代码。我如何避免相同的情况。我已将刷新控件添加到表视图中。如果ios版本超过11.0,我想将搜索栏加载到导航栏

refreshController.addTarget(self, action: #selector(refreshSelector), for: .valueChanged)
// Add Refresh Control to Table View
if #available(iOS 10.0, *) {
tableView.refreshControl = refreshController
} else {
tableView.addSubview(refreshController)
}

@objc func refreshSelector()
{
if(!searchLoaded)
{
searchLoaded = true
//self.tableView.tableHeaderView = searchController.searchBar
if #available(iOS 11.0, *) {
self.navigationItem.searchController = searchController
} else {
self.tableView.tableHeaderView = searchController.searchBar
}
//           self.refreshController.endRefreshing()
//  tableView.setContentOffset(CGPoint.zero, animated: true)
print( "Got ya")
self.navigationItem.rightBarButtonItem = nil
}
refreshController.endRefreshing()
// self.tableView.scrollToRow(at: IndexPath(row: 1, section: 0), at: UITableViewScrollPosition.top, animated: true)
//  self.refreshController.removeFromSuperview()

}

添加了UIRefreshControl

试试这个:

// Add Refresh Control to Table View
if #available(iOS 10.0, *) {
tableView.refreshControl = refreshControl
} else {
tableView.addSubview(refreshControl)
}

尝试更改 :

tableView.addSubview(refreshControl) to 
tableView.backgroundView = refreshControl

我也面临这个问题,并关注了这个博客:

  • https://cocoacasts.com/how-to-add-pull-to-refresh-to-a-table-view-or-collection-view

最新更新