Pan Gesture Recognizer in iOS4

Discussion in 'iOS Programming' started by ahan.tm, Dec 11, 2011.

  1. ahan.tm macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #1
    Hi,

    I am in huge trouble! My app currently uses PanGestureRecognizers to detect dragging of images around the screen. I used to use the touches began, touches moved, and touches ended methods. The problem with those was that the dragging of the images was choppy and would not follow the finger that well. So, I switched over to PanGestureRecognizers and now, it crashes when I try to run it on iOS 4. The PanGestures are in Interface Builder in Xcode 4.2. Does anybody have a solution to this problem or a way to overcome it?

    Here is the actual error in the debugger:

    Code:
    2011-12-11 21:28:12.538 iBehave[90966:bf03] -[UIPanGestureRecognizer initWithCoder:]: unrecognized selector sent to instance 0x5b6a850
    2011-12-11 21:28:12.541 iBehave[90966:bf03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPanGestureRecognizer initWithCoder:]: unrecognized selector sent to instance 0x5b6a850'
    *** Call stack at first throw:
    (
    	0   CoreFoundation                      0x016245a9 __exceptionPreprocess + 185
    	1   libobjc.A.dylib                     0x01453313 objc_exception_throw + 44
    	2   CoreFoundation                      0x016260bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    	3   CoreFoundation                      0x01595966 ___forwarding___ + 966
    	4   CoreFoundation                      0x01595522 _CF_forwarding_prep_0 + 50
    	5   UIKit                               0x008629fd UINibDecoderDecodeObjectForValue + 2592
    	6   UIKit                               0x008636ac -[UINibDecoder decodeObjectForKey:] + 398
    	7   UIKit                               0x0077893e -[UIRuntimeConnection initWithCoder:] + 153
    	8   UIKit                               0x00778ee7 -[UIRuntimeEventConnection initWithCoder:] + 64
    	9   UIKit                               0x008629fd UINibDecoderDecodeObjectForValue + 2592
    	10  UIKit                               0x008622f5 UINibDecoderDecodeObjectForValue + 792
    	11  UIKit                               0x008636ac -[UINibDecoder decodeObjectForKey:] + 398
    	12  UIKit                               0x00777c36 -[UINib instantiateWithOwner:options:] + 804
    	13  UIKit                               0x00779ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
    	14  UIKit                               0x0062f628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
    	15  UIKit                               0x0062d134 -[UIViewController loadView] + 120
    	16  UIKit                               0x0062d00e -[UIViewController view] + 56
    	17  UIKit                               0x005a0d42 -[UIWindow addRootViewControllerViewIfPossible] + 51
    	18  UIKit                               0x005a022d -[UIWindow _setHidden:forced:] + 303
    	19  UIKit                               0x005a001d -[UIWindow _orderFrontWithoutMakingKey] + 50
    	20  UIKit                               0x0059ecd1 -[UIWindow makeKeyAndVisible] + 39
    	21  iBehave                             0x00002b73 -[AppDelegate application:didFinishLaunchingWithOptions:] + 707
    	22  UIKit                               0x0057dc89 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
    	23  UIKit                               0x0057fd88 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
    	24  UIKit                               0x0058a617 -[UIApplication handleEvent:withNewEvent:] + 1533
    	25  UIKit                               0x00582abf -[UIApplication sendEvent:] + 71
    	26  UIKit                               0x00587f2e _UIApplicationHandleEvent + 7576
    	27  GraphicsServices                    0x0288e992 PurpleEventCallback + 1550
    	28  CoreFoundation                      0x01605944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
    	29  CoreFoundation                      0x01565cf7 __CFRunLoopDoSource1 + 215
    	30  CoreFoundation                      0x01562f83 __CFRunLoopRun + 979
    	31  CoreFoundation                      0x01562840 CFRunLoopRunSpecific + 208
    	32  CoreFoundation                      0x01562761 CFRunLoopRunInMode + 97
    	33  UIKit                               0x0057f7d2 -[UIApplication _run] + 623
    	34  UIKit                               0x0058bc93 UIApplicationMain + 1160
    	35  iBehave                             0x0000277a main + 170
    	36  iBehave                             0x000026c5 start + 53
    )
    terminate called throwing an exceptionsharedlibrary apply-load-rules all
    Current language:  auto; currently objective-c
    (gdb) 
    Thanks!!!
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    I'm not sure when pan gesture recognizers became available in nibs. If the answer is 5.0 then you can't use such a nib in 4.0. If you want to support 4.0 then you probably need to have separate nibs, one for 5.0 and one for 4.x. You need slightly different code that loads the correct nib based on the OS version. I believe that pan gesture recognizers became available in 3.2, so you should be able to create the recognizers in code if they aren't available in the nib. Alternatively you can just use the 4.0 scenario and then use the gesture recognizers in the nib when you drop support for 4.x. There are a few different ways to do this.
     
  3. ahan.tm thread starter macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #3
    Can I create them in code for both iOS 4 and 5 and keep the same code for the action? There is one method for all the recognizers(6) dragging.

    Thanks
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Yes, creating them in code in both OSes is one option.
     
  5. ahan.tm thread starter macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #5
    Thanks,

    It Works!:):)
     

Share This Page