I\'m trying to add a UIRefreshControl
to a UICollectionView
, but the problem is that the refresh control does not appear unless the collection view
You must check in api call if collection view is in refreshing state then end refreshing to dismiss refreshing control.
private let refreshControl = UIRefreshControl()
refreshControl.tintColor = .white
refreshControl.addTarget(self, action: #selector(refreshData), for: .valueChanged)
collectionView.addSubview(refreshControl)
@objc func refreshData() {
// API Call
}
// Disable refresh control if already refreshing
if refreshControl.isRefreshing {
refreshControl.endRefreshing()
}