【问题标题】:chaining performBatchUpdates for collectionview为 collectionview 链接 performBatchUpdates
【发布时间】:2017-04-10 01:40:40
【问题描述】:

链接performBatchUpdate 调用UICollectionView 的正确方法是什么,这样一个更新在下一个更新开始之前完成,以防止同时触发多个,从而导致 IndexPaths 不同步(由于删除混合在插入)

【问题讨论】:

    标签: ios swift uicollectionview


    【解决方案1】:

    我不太确定您在这里寻找什么。如果您的意思是在执行performBatchUpdate 时如何确保多个线程不会相互覆盖,您应该确保所有对performBatchUpdate 的调用都在主线程上调用。例如:

    DispatchQueue.main.async {
        collectionView.performBatchUpdates({
            // perform a bunch of updates.
        }, completion: { (finished: Bool) in 
            // anything that needs to happen after the update is completed.
        }
    }
    

    或者,如果您正在寻找一种在同一线程中多次调用 performBatchUpdates 的方法(是的,您需要这个有点奇怪,但我有一个地方需要,因为第三我正在使用的派对 API),因为 performBatchUpdates 有一个完成,您可以尝试将第二个 performBatchUpdates 调用放在第一个的完成处理程序中。

        self.collectionView.performBatchUpdates({
            // perform a bunch of updates.
        }, completion: { (finished: Bool) in
            self.collectionView.performBatchUpdates({
                // perform a bunch of other updates.
            }, completion: { (finished: Bool) in
            })
        })
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 2016-08-31
    • 2012-09-15
    相关资源
    最近更新 更多