2013-04-26 39 views
4

我尝试了所有可能的搜索,但是在一个星期内我没有找到任何类似的东西。 我正在制作一个显示表格视图的应用程序。单元格(由自定义类和Interface Builder生成)可以使用单元类中的UIPanGestureRecognizer进行拖动。 一切正常,只是罚款时,我按住上的小区,其错误的应用程序崩溃的手指:即使没有实施,uilongpressgesturerecognizer也会崩溃

-[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 EVERYWHERE(在单元类中,在tableview的类中),但错误仍然是一样的(我在主题中查看了许多线程并相信我,语法是正确的。

如果你想要的任何其他文件随意问(这是我的第一篇文章在这里,我不知道到底是什么,我必须展示)。

谢谢你们的宝贵帮助。

好问题仍然存在抱歉打扰:(我设法设置一个断点和打印堆栈跟踪。这是它:

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 

上的代码的应用程序块: 我通过截获UILongPressGestureRecognizer解决

-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer { 
CGPoint translation = [gestureRecognizer translationInView:[self superview]]; 

编辑,它是一种安全的方式?

-(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;} 
+0

显示在你的'xib'对象和任何相关的代码 – 2013-04-26 14:51:11

+0

细胞物体的图像是以下内容:http:// postimg。org/image/jnird1ifh /代码的问题是我没有编写任何有关UILongpressGestureRecognizer的代码,所以没有什么不寻常的我可以看到 – dado728 2013-04-26 14:58:08

+0

你的问题是使用自定义手势识别器,默认情况下已经集成到UITableView中:http:// developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html(阅读“重新排序表格行”部分 – 2013-04-26 15:08:18

回答

4

在你:

-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer 

尝试改变:

CGPoint translation = [gestureRecognizer translationInView:[self superview]]; 

要:

CGPoint translation = [gestureRecognizer locationInView:[self superview]]; 

希望这有助于。

+0

您天才!非常感谢,它非常完美!在开始时,我无法回滚到原单元格的位置,但我从[自我超级景观]改为自我,现在它工作完美:) – dado728 2013-05-02 08:31:31

+0

编辑:(它的作品,但现在我只能滑动第一两个单元,那么它不适用于其他单元,这些单元的高度不同,我正在研究不同大小是否会导致此错误发生...... – dado728 2013-05-02 22:33:45

14

我通过检查您收到的gestureRecognizer的类型来解决此问题。

有时我收到“UILongPressGestureRecognizer”而不是“UIPanGestureRecognizer”。

试试这个:

-(BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer { 
    if ([gestureRecognizer class] == [UIPanGestureRecognizer class]) { 
     CGPoint translation = [gestureRecognizer translationInView:[self superview]]; 

     return YES; 
    } 
    return NO; 
} 

更新

雨燕2.0的版本

override func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool { 
    guard let panGestureRecognizer = gestureRecognizer as? UIPanGestureRecognizer else { return false } 

    let translation = panGestureRecognizer.translationInView(self.superview) 
} 
+0

这是此问题的正确解决方案 – MusiGenesis 2014-04-15 18:37:56

+0

此解决方案已运行在我的情况下对我更好。 – 2014-05-29 07:04:59

+0

非常好 - 任何想法为什么这可能是一个问题呢? – trdavidson 2015-04-05 18:53:01