UITapGestureRecognizer causes app to crash

安稳与你 提交于 2019-12-11 09:38:48

问题


UITapGestureRecognizer causes app to crash when a swipe is done. Swipes done over very short distances do not cause any problems, but those done over a longer distance give the error :

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

where 0x17ee27c0 is a random value.

*** 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) is from tapGestureRecognizer._imp

This is happening on multiple devices running iOS 8.1 . The source is compiled on Xcode 6.

Here is how I declare the UITapGestureRecognizer:

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

And here is the method:

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

The UITapGestureRecognizer is placed on a SKView;

Here is the stack trace: http://imageshack.com/a/img903/3622/X9QFX0.png


回答1:


I had the same issue in one of my SpriteKit Games, it is caused when you use gestures during transition between scenes, i solved it by setting gestureRecognizer.enable property (documentation) to NO before the transition.




回答2:


you are trying to run a selector called name on a UITapGestureRecognizer instance, but UITapGestureRecognizer doesn't have such a selector and that's why your program is crashing. Check where you are calling name (probably inside viewTapped) and make sure you are applying it on the correct object.




回答3:


Are you sure ViewTapped: is expecting an argument.



来源:https://stackoverflow.com/questions/26610145/uitapgesturerecognizer-causes-app-to-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!