我想将UIMenuController
与UITableViewCell
,
所以我在我的单元格中的自定义标签中添加UILongPressGestureRecognizer
,如
-(BOOL)canBecomeFirstResponder
{
return YES;
}
-(void)longPress:(UILongPressGestureRecognizer *)longRecognizer
{
if (longRecognizer.state!=UIGestureRecognizerStateBegan) {
return;
}
[self becomeFirstResponder];
UIMenuItem *copy = [[UIMenuItem alloc] initWithTitle:@"copy" action:@selector(copyText:)];
UIMenuItem *report = [[UIMenuItem alloc] initWithTitle:@"report" action:@selector(reportText:)];
UIMenuController *menu = [UIMenuController sharedMenuController];
[menu setMenuItems:@[copy, report]];
[menu setTargetRect:longRecognizer.view.bounds inView:longRecognizer.view];
[menu setMenuVisible:YES animated:YES];
NSLog(@"menu show");
}
但我在[self becomeFirstResponder]
和控制台日志显示
_BSMachError: (os/kern) invalid capability (20)
_BSMachError: (os/kern) invalid name (15)