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
You could pass in the NSIndexPath
of the selected cell in the userInfo
dictionary of your notification. You could set that in the tag
of your custom cell when it is created.
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 <objc/runtime.h>
#import <objc/message.h>
__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.
I had the same issue. My app would crash when I tried to insert a cell into my UICollectionView
after I had selected text in a UITextField
which was placed inside a collectionViewCell. My fix was to resign the first responder before the insertion happened. Since I was using a NSFetchedResultsController
to handle the updating I put this at the beginning of controllerWillChangeContent:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller {
[[UIApplication sharedApplication].keyWindow findAndResignFirstResponder];
...
}
I found findAndResignFirstResponder
from this SO answer