Swift 4-垂直UICollectionView上的UIRefreshControl滞后

时间:2018-11-12 12:06:34

标签: swift uirefreshcontrol

由于某种原因,我很难刷新。我的意思是,要刷新,我必须从收藏视图的最上端开始,然后向下滚动到最底部...有时,我什至必须使用第二根手指才能滚动更多以使其正常工作!

这是初始化刷新的方法:

private var refresher: UIRefreshControl!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.

    refresher = UIRefreshControl()

    refresher.addTarget(self, action: #selector(self.requestRefreshContent), for: .valueChanged)

    if #available(iOS 10.0, *) {
        schoolPostsCollectionView.refreshControl = refresher
    }
    else {
        schoolPostsCollectionView.addSubview(refresher)
    }

    refresher.beginRefreshing()
}

这是我叫beginRefreshing()的方式:

private func getContentOfSchool() {
    someBackgroundServerCall() {
        // some code

        ...

        DispatchQueue.main.async {
            self.refresher.endRefreshing()
            self.schoolPostsCollectionView.reloadData()
        }
    }
}

知道为什么会这样吗?

1 个答案:

答案 0 :(得分:0)

尝试这个。...

refresher = UIRefreshControl()
    refresher.attributedTitle = NSAttributedString(string: "Refreshing...", attributes: nil)
    refresher.tintColor = UIColor.black
    refresher.addTarget(self, action: #selector(self.requestRefreshContent), for: .valueChanged)

    if #available(iOS 10.0, *) {
        schoolPostsCollectionView.refreshControl = refresher
    } else {
        schoolPostsCollectionView.backgroundView = refresher
    }