UIMenu popovers in CollectionView

This is how I installed popovers

UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Delete Patient" action:@selector(customAction:)]; [[UIMenuController sharedMenuController] setMenuItems:@[menuItem]]; 

and then add the required methods

 - (BOOL)canBecomeFirstResponder { return YES; } - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { NSLog(@"canPerformAction"); // The selector(s) should match your UIMenuItem selector if (action == @selector(customAction:)) { return YES; } return NO; } - (void) customAction:(id) sender { for (Treatment *t in self.ptToDelete.patientRx) { [self.managedObjectContext deleteObject:t]; } [self.managedObjectContext deleteObject:self.ptToDelete]; NSError *error = nil; if (![self.managedObjectContext save:&error]) { NSLog(@"Error! %@", error); } } 

This works for iOS6, but now it is not. The next method is not called, it should be called when I press and hold

 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender 
+2
source share
1 answer

I found that I need to have the following in my CollectionViewCell class. However, this was not required in ios6. Hope this saves someone a few hours.

 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { // The selector/s should match your UIMenuItem selector if (action == @selector(customAction:)) { return YES; } return NO; } - (void) customAction:(id)sender { // do stuff } 
+7
source

Source: https://habr.com/ru/post/946964/


All Articles