2

这就是我设置弹出框的方式

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
4

1 回答 1

7

我发现我的 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
}
于 2013-09-14T06:34:17.283 回答