这就是我设置弹出框的方式
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