繁体   English   中英

reloadData()不适用于refreshControl

[英]reloadData() doesn't work with refreshControl

我有管理很多单元的UICollectionView。 当我删除一个单元格时,我希望该单元格通过refreshControl消失。 但是我不明白为什么reloadData不起作用。 如果有人可以帮助我提前谢谢您。

在我看来didLoad:

self.collectionView!.alwaysBounceVertical = true
let refresher = UIRefreshControl()
refresher.tintColor = MyColor.Color
refresher.addTarget(self, action: #selector(PublicListController.refreshStream), forControlEvents: .ValueChanged)
refreshControl = refresher
collectionView!.addSubview(refreshControl!)

collectionView.dataSource = self
self.populateDataBest()

我的简单功能:

func refreshStream() {
    collectionView?.reloadData()
    refreshControl?.endRefreshing()
}

我用populateDataBest方法完成了CollectionView:

 func populateDataBest() {
    self.videosService.get(true, completionHandler: {
        videosBest, error in
        dispatch_async(dispatch_get_main_queue(), {
            if error != nil {
                if error!.code == -999 {
                    return
                }
                self.displayError(informations.LocalizedConnectionError)
                return
            }
                self.bestClip = videosBest
                for (indexBest, _) in (self.bestClip?.enumerate())! {
                    let videoBest:Clip = self.bestClip![indexBest]
                    self.pictureArrayVideo.addObject(["clip": videoBest, "group": "BEST"])
                }
                 self.dataSource.updateData(self.pictureArrayVideo)
                 self.collectionView.reloadData()
        })
    })
}

并且第一次重载工作在我的方法populateDataBest的末尾。

编辑:

我尝试实现删除元素的函数(我目前仅出于测试目的将0放入参数remove方法中)

func refreshStream() {
      dispatch_async(dispatch_get_main_queue(), {
        self.remove(0)
        self.collectionView.reloadData()
    })
     self.refreshControl.endRefreshing()
}

func remove(i: Int) {
    self.listForPager.removeAtIndex(i)
    let indexPath: NSIndexPath = NSIndexPath(forRow: i, inSection: 0)
    self.collectionView.performBatchUpdates({
        self.collectionView.deleteItemsAtIndexPaths(NSArray(object: indexPath) as! [NSIndexPath])
        }, completion: {
            (finished: Bool) in
            self.collectionView.reloadItemsAtIndexPaths(self.collectionView.indexPathsForVisibleItems())
    })
}

我有这个错误

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0.  The number of items contained in an existing section after the update (8) must be equal to the number of items contained in that section before the update (8), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'

有人知道为什么,可以帮助我吗?

提前谢谢。

如果您要从数组中骑行集合,则还应删除该项目,因为该行将消失并最终重新加载。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM