0

I am having a major trouble while I am trying to drag a UICollectionViewCell far away to trigger deletion. The way I do is hide the cell on long press, copy the cell contents to a new UIView which moves around with the finger. It works except when there is only one element in UICollectionView and is dragged with finger far away to trigger deletion. Here is what I get :

    -[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

The problem doesn't happen if I choose not hide the cell in prepareLayout call.

    if ([self.selectedIndexPath isEqual:indexPath]) {
    //  attributes.hidden = YES;
    }

Looks like a bug in iOS but this should be noticed by a lot of developers, what is a fix or a workaround ?

Deepak Sharma
  • 5,577
  • 7
  • 55
  • 131
  • what do you mean with "copy the cell contents"? Are there some connections between your "copy"-view and the original cell or just the rendered image? – Jonathan Cichon Jul 22 '13 at 09:12
  • Hello Jonathan, well I just make a copy of the view contents as a UIImage using the following code : `- (UIImage *)toImageWithSize:(CGSize)size { UIGraphicsBeginImageContextWithOptions(size, NO, 0.0); [self.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; }` – Deepak Sharma Jul 23 '13 at 04:43
  • 2
    ok, so there should be no connection between you copy-view and the original cell. As you are setting `hidden` to `YES`, which according to the documentation might lead to a cell being not created at all, might lead to the destruction of your cell in this case. Try setting the alpha attribute to `0` instead. – Jonathan Cichon Jul 23 '13 at 06:23
  • Yes that's a nice workaround, thanks ! Not sure why it should crash by setting attributes.hidden = YES, but will file a bug soon. – Deepak Sharma Jul 24 '13 at 11:27

0 Answers0