Deleting cells from UICollectionView via NSNotification

后端 未结 3 1538
栀梦
栀梦 2020-12-31 17:11

I have a simple UICollectionView based app - one UICollectionView and a NSMutableArray based data model for simplicity.

I can delete cells with no problem via the di

3条回答
  •  太阳男子
    2020-12-31 17:58

    I found a crude but working workaround, and it even checks if action is already implemented in a future release (better than a category)

    // Fixes the missing action method when the keyboard is visible
    #import 
    #import 
    __attribute__((constructor)) static void PSPDFFixCollectionViewUpdateItemWhenKeyboardIsDisplayed(void) {
        @autoreleasepool {
        if ([UICollectionViewUpdateItem class] == nil) return; // pre-iOS6.
        if (![UICollectionViewUpdateItem instancesRespondToSelector:@selector(action)]) {
                IMP updateIMP = imp_implementationWithBlock(^(id _self) {});
                Method method = class_getInstanceMethod([UICollectionViewUpdateItem class], @selector(action));
                const char *encoding = method_getTypeEncoding(method);
                if (!class_addMethod([UICollectionViewUpdateItem class], @selector(action), updateIMP, encoding)) {
                    NSLog(@"Failed to add action: workaround");
                }
            }
        }
    }
    

    Edit: Added check for iOS5.
    Edit2: We're shipping that in lots of commercial projects (http://pspdfkit.com) and it works great.

提交回复
热议问题