0

我向 UIWebView 实例添加了一个自定义弹出菜单:

- (void)viewDidLoad
{
    UILongPressGestureRecognizer* gesture = [[[UILongPressGestureRecognizer alloc] 
    initWithTarget:self action:@selector(handleGesture::)] autorelease];
}

- (void)handleGesture
{

}

- (void)handleGesture:(UIGestureRecognizer*)gestureRecognizer
{
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
        [gestureRecognizer.view becomeFirstResponder];
        UIMenuController* mc = [UIMenuController sharedMenuController];
        [mc setTargetRect: gestureRecognizer.view.frame inView: gestureRecognizer.view.superview];
        [mc setMenuVisible: YES animated: YES];
}

它有效!直到我将 textarea(CodeMirror 编辑器)聚焦在网页上。在这种情况下,我有以下例外:

-[FirstViewController handleGesture::]: unrecognized selector sent to instance 0x20369c00
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FirstViewController handleGesture::]: unrecognized selector sent to instance 0x20369c00'
*** First throw call stack:
(0x3608c2a3 0x3439c97f 0x3608fe07 0x3608e531 0x35fe5f68 0x3747ad31 0x374423dd 0x3762f479 0x37366837 0x3736529b 0x360616cd 0x3605f9c1 0x3605fd17 0x35fd2ebd 0x35fd2d49 0x3650f2eb 0x373b1301 0x140bb 0x14060)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

我认为需要使用外来参数实现未记录版本的 handleGesture 选择器。这样对吗?如何找到需要什么样的参数?

4

1 回答 1

0

正确的代码:

initWithTarget:self action:@selector(handleGesture:)] autorelease];
于 2012-11-03T18:36:14.300 回答