9

i am getting an NSInvalidArgumentException with reason: -[UITapGestureRecognizer initWithCoder:]: unrecognized selector sent to instance

my understanding was that UITapGestureRecognizers were supported in ios4.x?

is it possible to load a different xib file for sub ios5 versions?

Vin
  • 10,517
  • 10
  • 58
  • 71
Andy
  • 105
  • 6
  • 2
    They are supported in 4.x, the thing is that you can't just drop them in xib (I suppose that's the case here). You cant either set it in code or make another xib and load it after version check. – ksh Jan 26 '12 at 14:25
  • Check out [this potentially related question](http://stackoverflow.com/questions/6520932/uigesturerecognizer-in-uiview-object). It may be that you need to instantiate your UITapGestureRecognizers a different way. – Michael Dautermann Jan 26 '12 at 14:26
  • Seems to me that your recognizer is getting deallocated... UIGestureRecognizer does not respond to -initWithCoder: and that's why it's crashing. (I think that the deallocate pointer to your UIGestureRecognoizer object is being taken over by an other object, which is supposed to respond to initWithCoder:...) –  Jan 26 '12 at 15:56

2 Answers2

16

As @mit3z states in his comment on the original question, iOS 4.3 supports this feature only when setup up manually with code. It is not supported with Interface Builder.

Apple would have saved us all grief over this if they simply added this as a build-time warning.

benvolioT
  • 4,507
  • 2
  • 36
  • 30
  • 1
    This solved my problem. For a quick way to add the GestureRecognizer via code, check out the answer here: http://stackoverflow.com/questions/5954934/issue-with-a-uitapgesturerecognizer – Ryan Bavetta Apr 04 '12 at 17:57
1

I think you have a NSCoding compliant object that is deallocated before the crash. The UITapGestureRecognizer is allocated at its address and when the disappeared object (but not its reference) tries to call initWithCoder on itself, it actually calls this method on your gestureRecognizer instead.

Then your problem comes from that deallocated object but not from your gestureRecognizer.

Be sure to retain all your IBOutlet properties.

Vincent Zgueb
  • 1,491
  • 11
  • 11
  • You can't both use ARC and call retain. If calls to retain compile, you're not using ARC. – Catfish_Man Feb 08 '12 at 04:10
  • I would assume he means he is `strong` typing or `retain` typing his IBOutlet properties, not actually calling retain on the objects themselves. If he were actually calling `retain` with arc, the code wouldn't compile. – btomw Mar 21 '13 at 14:00