我尝试了所有可能的搜索,但一周内没有找到任何类似的东西。
我正在制作一个显示表格视图的应用程序。单元格(由自定义类和 Interface Builder 创建)可以使用 UIPanGestureRecognizer 进行拖动,该 UIPanGestureRecognizer 是 Cell 类中的 pu 。
一切正常,除了当我将手指按住单元格时,应用程序崩溃并出现错误:
-[UILongPressGestureRecognizer translationInView:]: unrecognized selector sent to instance 0x94670a0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILongPressGestureRecognizer translationInView:]: unrecognized selector sent to instance 0x94670a0'
我知道它的含义(通常是发送到实例的错误参数),但我真的不知道这怎么可能,因为我的代码中没有 UILongPressGestureRecognizer 的痕迹。
我试图在任何地方拦截 LongPressGestureREcognizer (在单元格类中,在表视图的类中,在分配每个单元格之前),但错误仍然是相同的(我查看了主题中的许多线程并相信我,语法是正确的。
如果您需要任何其他文档,请随时询问(这是我在这里发表的第一篇文章,我不知道我到底要展示什么)。
感谢您的宝贵帮助。
好吧,问题仍然存在,抱歉打扰:( 我设法设置一个断点并打印堆栈跟踪。这里是:
0 uBellow 0x0000ac57 -[OpinionCell gestureRecognizerShouldBegin:] + 71
1 UIKit 0x00914939 -[UIGestureRecognizer _shouldBegin] + 1334
2 UIKit 0x0091181a -[UIGestureRecognizer setState:] + 152
3 UIKit 0x00921cea -[UILongPressGestureRecognizer enoughTimeElapsed:] + 127
4 libobjc.A.dylib 0x017186b0 -[NSObject performSelector:withObject:] + 70
5 UIKit 0x00787954 -[UIDelayedAction timerFired:] + 83
6 Foundation 0x0114d2c0 __NSFireTimer + 97
7 CoreFoundation 0x01bce376 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
8 CoreFoundation 0x01bcde06 __CFRunLoopDoTimer + 534
9 CoreFoundation 0x01bb5a82 __CFRunLoopRun + 1810
10 CoreFoundation 0x01bb4f44 CFRunLoopRunSpecific + 276
11 CoreFoundation 0x01bb4e1b CFRunLoopRunInMode + 123
12 GraphicsServices 0x022337e3 GSEventRunModal + 88
13 GraphicsServices 0x02233668 GSEventRun + 104
14 UIKit 0x00648ffc UIApplicationMain + 1211
15 uBellow 0x0000287d main + 141
16 uBellow 0x000027a5 start + 53
应用程序阻止代码:
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
CGPoint translation = [gestureRecognizer translationInView:[self superview]];
编辑
我通过拦截 UILongPressGestureRecognizer 解决了,这是一种安全的方法吗?
-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer {
if([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]]){
return NO;
}else{
CGPoint translation = [gestureRecognizer translationInView:[self superview]];
// Check for horizontal gesture
if (fabsf(translation.x) > fabsf(translation.y)){
return YES;
}
}
return NO;}