UITapGestureRecognizer导致应用程序崩溃

问题描述 投票:1回答:4

UITapGestureRecognizer导致应用程序在滑动后崩溃。在很短的距离上完成刷卡不会引起任何问题,但是在更长的距离上进行刷卡会产生错误:

 -[UITapRecognizer name]: unrecognized selector sent to instance 0x17ee27c0

其中0x17ee27c0是随机值。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITapRecognizer name]: unrecognized selector sent to instance 0x17ee27c0'
*** First throw call stack:
(0x2cb7dc1f 0x3a328c8b 0x2cb83039 0x2cb80f57 0x2cab2df8 0x2feee1c1 0x2d7d01cf 0x3024822d 0x300671ad 0x30066bcd 0x3003d3dd 0x302b0c29 0x3003be39 0x2cb44377 0x2cb43787 0x2cb41ded 0x2ca90211 0x2ca90023 0x33e890a9 0x3009c1d1 0xdca87 0x3a8a8aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException

UITapRecognizer *(0x17ee27c0)来自tapGestureRecognizer._imp

这在运行iOS 8.1的多个设备上发生。源代码是在Xcode 6上编译的。

这是我声明UITapGestureRecognizer的方式:

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTapped:)];
[myView addGestureRecognizer:tapGestureRecognizer];      

这是方法:

- (void)viewTapped:(UITapGestureRecognizer *)sender { }

UITapGestureRecognizer放置在SKView上;

这里是堆栈跟踪:http://imageshack.com/a/img903/3622/X9QFX0.png

objective-c crash uitapgesturerecognizer swipe-gesture
4个回答
1
投票

您正在尝试在name实例上运行一个名为UITapGestureRecognizer的选择器,但是UITapGestureRecognizer没有这样的选择器,这就是您的程序崩溃的原因。检查要在哪里调用name(可能在viewTapped内部),并确保将其应用于正确的对象。


1
投票

我在一个SpriteKit游戏中遇到了相同的问题,这是由于您在场景之间的过渡期间使用手势引起的,我通过在过渡之前将gestureRecognizer.enable属性(documentation)设置为NO来解决了此问题。


1
投票

您确定ViewTapped:正在等待一个参数。


0
投票

您可以使用强制转换为例:action as MyTapGesture

© www.soinside.com 2019 - 2024. All rights reserved.