UIRefreshControl on UICollectionView only works if the collection fills the height of the container

前端 未结 7 1288
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 05:35

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

7条回答
  •  北海茫月
    2020-12-02 05:49

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

提交回复
热议问题