为什么要成为第一个响应者导致iOS崩溃?

时间:2016-09-05 09:14:51

标签: ios

我想将UIMenuControllerUITableViewCell

一起使用

所以我在我的单元格中的自定义标签中添加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)

发生了什么?

0 个答案:

没有答案