我正在使用嵌入在UITabBarController和UINavigationController中的UICollectionViewController,并且当我在选项卡之间多次切换时,偶尔会遇到一个错误,即我不希望刷新控件出现在标题上方。
var refreshControl: UIRefreshControl = {
let refreshControl = UIRefreshControl()
refreshControl.tintColor = UIColor.primaryRed
return refreshControl
}()
refreshControl.addTarget(self, action: #selector(refreshData), for: .valueChanged)
collectionView?.refreshControl = refreshControl
@objc private func refreshData() {
refreshControl.beginRefreshing()
datasource.fetchEvents {
self.refreshControl.endRefreshing()
self.collectionView?.reloadData()
}
}