使用CATransaction批量更新UITableView时出现UITableViewAlertForLayoutOutsideViewHierarchy错误

我的应用使用了tableView,该更新通过批量更新进行了更新。

单元格的indicatorImage取决于表的部分。 当单元格在各部分之间移动时,此指示器会发生变化,我想为指示器图像的变化设置动画。
为此,我首先使用tableView.performBatchUpdates为单元格的删除,插入和移动设置动画。
其次,我将批量更新嵌入到CATransaction块中,以动画化图像更改。

除了一个例外,这非常有效: 如果在表视图更新期间应显示警报,则我的应用程序将在UITableViewAlertForLayoutOutsideViewHierarchy断点处停止。

这是代码:

CATransaction.begin()
tableView.performBatchUpdates({ 
    tableView.deleteRows(at: deletions,with: .automatic)
    tableView.insertRows(at: insertions,with: .automatic)
    for (from,to) in movements {
        tableView.moveRow(at: from,to: to)
        if from.section == kTableSectionBought {
            if let cell = tableView.cellForRow(at: from) {
                let indicatorImage = to.section < 2 ? self.progressImages!.first : self.progressImages!.last
                UIView.transition(with: cell.imageView!,// see <https://stackoverflow.com/a/40472115/1987726>
                                                    duration: 0.25,options: .transitionCrossDissolve,animations: { cell.imageView!.image = indicatorImage },completion: nil)
            }
        }
    }
    animateCells(deletions: deletions,movements: movements)
},completion: { (finished) in
    // some code
}  

我的问题是:

该错误的可能原因是什么,我该如何避免?

PS:我读过this question,但没有答案,相反,我的UIWindow已定义。

yingq0072 回答:使用CATransaction批量更新UITableView时出现UITableViewAlertForLayoutOutsideViewHierarchy错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2969392.html

大家都在问