长按手势问题

时间:2012-03-23 21:45:15

标签: iphone ios4 uigesturerecognizer

我在我的应用程序中长按手势,它在ios 5.0中运行良好但在ios 4.3中我有例外。这就是我在debug

中看到的内容
[UILongPressGestureRecognizer initWithCoder:]: unrecognized selector sent to instance 0x5863360
2012-03-23 23:39:30.384 Woods2[289:ef03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UILongPressGestureRecognizer initWithCoder:]: unrecognized selector sent to instance 0x5863360'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x013415a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x01ce6313 objc_exception_throw + 44
    2   CoreFoundation                      0x013430bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x012b2966 ___forwarding___ + 966
    4   CoreFoundation                      0x012b2522 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x005bb9fd UINibDecoderDecodeObjectForValue + 2592
    6   UIKit                               0x005bb2f5 UINibDecoderDecodeObjectForValue + 792
    7   UIKit                               0x005bc6ac -[UINibDecoder decodeObjectForKey:] + 398
    8   UIKit                               0x004d0c54 -[UINib instantiateWithOwner:options:] + 834
    9   UIKit                               0x004d2ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    10  UIKit                               0x00388628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
    11  UIKit                               0x00386134 -[UIViewController loadView] + 120
    12  UIKit                               0x0038600e -[UIViewController view] + 56
    13  Woods2                              0x00004f37 -[FirstViewController viewDidLoad] + 1671
    14  UIKit                               0x00386089 -[UIViewController view] + 179
    15  UIKit                               0x00398f54 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 120
    16  UIKit                               0x00397aaa -[UITabBarController transitionFromViewController:toViewController:] + 64
    17  UIKit                               0x003998a2 -[UITabBarController _setSelectedViewController:] + 263
    18  UIKit                               0x00399d5e -[UITabBarController viewWillLayoutSubviews] + 170
    19  UIKit                               0x004aa2e9 -[UILayoutContainerView layoutSubviews] + 226
    20  QuartzCore                          0x019faa5a -[CALayer layoutSublayers] + 181
    21  QuartzCore                          0x019fcddc CALayerLayoutIfNeeded + 220
    22  QuartzCore                          0x019a20b4 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310
    23  QuartzCore                          0x019a3294 _ZN2CA11Transaction6commitEv + 292
    24  UIKit                               0x002d89c9 -[UIApplication _reportAppLaunchFinished] + 39
    25  UIKit                               0x002d8e83 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690
    26  UIKit                               0x002e3617 -[UIApplication handleEvent:withNewEvent:] + 1533
    27  UIKit                               0x002dbabf -[UIApplication sendEvent:] + 71
    28  UIKit                               0x002e0f2e _UIApplicationHandleEvent + 7576
    29  GraphicsServices                    0x015eb992 PurpleEventCallback + 1550
    30  CoreFoundation                      0x01322944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    31  CoreFoundation                      0x01282cf7 __CFRunLoopDoSource1 + 215
    32  CoreFoundation                      0x0127ff83 __CFRunLoopRun + 979
    33  CoreFoundation                      0x0127f840 CFRunLoopRunSpecific + 208
    34  CoreFoundation                      0x0127f761 CFRunLoopRunInMode + 97
    35  UIKit                               0x002d87d2 -[UIApplication _run] + 623
    36  UIKit                               0x002e4c93 UIApplicationMain + 1160
    37  Woods2                              0x00001c2a main + 170
    38  Woods2                              0x00001b75 start + 53
)
terminate called throwing an exceptionkill

非常感谢您的帮助

以下是viewdidload中的一些代码

 UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] 
                                      initWithTarget:self action:@selector(handleLongPress:)];
lpgr.minimumPressDuration = 0.2; //user needs to press for 2 seconds
[mapView addGestureRecognizer:lpgr];
[lpgr release];

1 个答案:

答案 0 :(得分:1)

现在可以更好地格式化跟踪数据。现在我看到它正在loadFromNib上发生,即使用户执行长按也没有。特别是如果从另一个项目复制了笔尖,这是有道理的。

请查看您是否可以在笔尖中找到手势识别器。如果它在那里,请检查连接检查器。它可能有一些无效的引用,可能是另一个项目中的符号。 (您可能会在一个或多个连接附近看到一点“!”)。

如果你发现了,那么问题就解决了。删除它,并使用您在代码中设置的GR。 (或重新配置nib中的指针并注释掉viewDidLoad中的代码:)。