Closed simonbs closed 11 years ago
It seems that while animating (in animation block and completion block), querying of the index path of cell result in the collection view returning nil
. I haven't read this behavior in the documentation so it seems a surprise for me.
Luckily, we could dispatch the query immediately after with the following code.
- (void)collectionView:(UICollectionView *)theCollectionView layout:(UICollectionViewLayout *)theLayout didEndReorderingAtIndexPath:(NSIndexPath *)theIndexPath {
double delayInSeconds = 0.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
UICollectionViewCell *cell = [theCollectionView cellForItemAtIndexPath:theIndexPath]; // cell available
NSLog(@"%@", cell);
});
}
I apply an animation to cells when they can be moved. Much like Apple does when reordering apps on the springboard. The animation disappears after a cell has been moved. This is not a problem, I can just apply it again afterwards but it's not possible to grab the cell again as
cellForItemAtIndexPath:
will return null for the index path which the cell was moved to.Example: