当我试图将 UICollectionViewCell 拖得很远以触发删除时,我遇到了很大的麻烦。我的做法是在长按时隐藏单元格,将单元格内容复制到一个新的 UIView 中,该 UIView 会随着手指移动。它可以工作,除非 UICollectionView 中只有一个元素并且用手指拖得很远以触发删除。这是我得到的:
-[UIViewAnimationContext completionHandler]: message sent to deallocated instance 0xac38660
(lldb) bt
* thread #1: tid = 0x1c03, 0x0307da97 CoreFoundation`___forwarding___ + 295,
stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x0307da97 CoreFoundation`___forwarding___ + 295
frame #1: 0x0307d94e CoreFoundation`_CF_forwarding_prep_0 + 14
frame #2: 0x01fab51a UIKit`-[UICollectionView _updateAnimationDidStop:finished:context:] + 1460
frame #3: 0x01ad6d66 UIKit`-[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 237
frame #4: 0x01ad6753 UIKit`+[UIViewAnimationState popAnimationState] + 2353
frame #5: 0x01ae31cc UIKit`+[UIView(Animation) commitAnimations] + 36
frame #6: 0x01faab7f UIKit`-[UICollectionView _updateWithItems:] + 2774
frame #7: 0x01fa7bdb UIKit`-[UICollectionView _endItemAnimations] + 13286
frame #8: 0x01fa460e UIKit`-[UICollectionView _updateRowsAtIndexPaths:updateAction:] + 335
frame #9: 0x01fa467b UIKit`-[UICollectionView deleteItemsAtIndexPaths:] + 48
如果我选择不在 prepareLayout 调用中隐藏单元格,则不会发生此问题。
if ([self.selectedIndexPath isEqual:indexPath]) {
// attributes.hidden = YES;
}
看起来像 iOS 中的一个错误,但这应该被很多开发人员注意到,什么是修复或解决方法?