gpt4 book ai didi

ios - reloadData() 不适用于 refreshControl

转载 作者:行者123 更新时间:2023-11-28 16:05:07 25 4
gpt4 key购买 nike

我有一个管理大量单元格的 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 结束时工作..

编辑:

我尝试实现删除我的元素的函数(我在 remove 方法的参数中放入 0 只是为了我的测试)

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).'

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

提前致谢。

最佳答案

如果您从一个数组中骑着您的收藏,您还应该删除该行的项目,因为该行将消失并最终重新加载。

关于ios - reloadData() 不适用于 refreshControl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40403765/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com