长按 tableViewCell 出现 UIMenuController 的方法
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = [UIColor clearColor];
UILongPressGestureRecognizer *longPress = [[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressAction:)] autorelease];
[self addGestureRecognizer:longPress];
}
return self;
}
- (BOOL)canBecomeFirstResponder
{
return YES;
}
- (void)longPressAction:(UILongPressGestureRecognizer *)longPress
{
if (longPress.state == UIGestureRecognizerStateBegan)
{
[self becomeFirstResponder];
UIMenuController *mc = [UIMenuController sharedMenuController];
UIMenuItem *delItem = [[[UIMenuItem alloc] initWithTitle:ZLocalizedString(@"Delete") action:@selector(deleteAction:)] autorelease];
mc.menuItems = [NSArray arrayWithObject:delItem];
[mc setArrowDirection:UIMenuControllerArrowDown];
CGPoint p = [longPress locationInView:self];
[mc setTargetRect:CGRectMake(p.x, p.y, 20, 20) inView:self];
[mc setMenuVisible:YES animated:YES];
}
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
return (action == @selector(deleteAction:));
}
- (void)deleteAction:(id)sender
{
}