Crash while long press on the tableview

2019-07-24 04:42发布

问题:

i have one tableview that have custom cells and one cell contains uiimageview,uilabels . When I pressed and hold and move uitableviewcell , sometimes I get crash with this logs.How can I remove this crash. I didn't use any gesture recognizer in my app and also i didn't use any tap or touch detection.I used only tableview delegate and datasource methods. Thanx for any help!

'-[CALayer _longPressGestureRecognized:]: unrecognized selector sent to instance 0x10d060'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x367cd64f __exceptionPreprocess + 114
    1   libobjc.A.dylib                     0x33a26c5d objc_exception_throw + 24
    2   CoreFoundation                      0x367d11bf -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
    3   CoreFoundation                      0x367d0649 ___forwarding___ + 508
    4   CoreFoundation                      0x36747180 _CF_forwarding_prep_0 + 48
    5   CoreFoundation                      0x3673af03 -[NSObject(NSObject) performSelector:withObject:] + 22
    6   UIKit                               0x35649f93 -[UIGestureRecognizer _updateGestureWithEvent:] + 562
    7   UIKit                               0x35649d57 -[UIGestureRecognizer _delayedUpdateGesture] + 22
    8   UIKit                               0x355b4afd _UIGestureRecognizerUpdateObserver + 436
    9   CoreFoundation                      0x367a4a35 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 16
    10  CoreFoundation                      0x367a6465 __CFRunLoopDoObservers + 412
    11  CoreFoundation                      0x367a775b __CFRunLoopRun + 854
    12  CoreFoundation                      0x36737ec3 CFRunLoopRunSpecific + 230
    13  CoreFoundation                      0x36737dcb CFRunLoopRunInMode + 58
    14  GraphicsServices                    0x35ef141f GSEventRunModal + 114
    15  GraphicsServices                    0x35ef14cb GSEventRun + 62
    16  UIKit                               0x355e1d69 -[UIApplication _run] + 404
    17  UIKit                               0x355df807 UIApplicationMain + 670
    18  MyAppName                          0x000029a7 main + 70
    19  MyAppName                          0x0000295c start + 40
)

回答1:

You can try intercepting the call by adding one to your cells. This does not conflict with the ability to drag and move cells in the edit mode. My table works fine for both.

In my - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

I attach one to each cell:

UILongPressGestureRecognizer *longPressGesture =
[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
[cell addGestureRecognizer:longPressGesture];
[longPressGesture release];


回答2:

Could you post some more details regarding how you have declared your tableview? If it is declared as editable, then you can long-press and drag it using the three lines present on the right-end of the cell, otherwise it will crash since the view doesn't know what to do with the long-press gesture.