UIMenu在CollectionView中popup
这是我如何设置popovers
UIMenuItem *menuItem = [[UIMenuItem alloc] initWithTitle:@"Delete Patient" action:@selector(customAction:)]; [[UIMenuController sharedMenuController] setMenuItems:@[menuItem]];
然后添加require方法
- (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); } }
这适用于iOS6,但现在不是。 下面的方法没有被调用,当我点击并按住时,应该调用它
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
我发现我需要在我的CollectionViewCell类中具有以下内容。 但是这不是ios6所要求的。 希望这可以节省几个小时。
- (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 }