[iPad] Popover deallocs while still showing [Solved]

Discussion in 'iOS Programming' started by ianprime0509, Aug 31, 2010.

  1. ianprime0509 macrumors newbie

    Joined:
    Aug 31, 2010
    #1
    I'm trying to present a popover when a user performs a long press on a button. I know about the gesture recognizers, but is there a way to make them only detect gestures on top of a button? I have many buttons so I don't want to have to loop though each one with the recognizer.

    EDIT: See below for new issue
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Just apply the gesture to the button directly via addGestureRecognizer:
     
  3. pflau macrumors 6502

    Joined:
    Sep 17, 2007
    #3
    Just check the view again the UIButton object. Remember that a UIButton is a subclass of UIView. You only need one gesture recognizer.
     
  4. ianprime0509 thread starter macrumors newbie

    Joined:
    Aug 31, 2010
    #4
    Great, the gesture is working now, but here's the new problem:

    I have a popover that shows when the gesture is performed, and it shows up fine, but when I do anything (such as releasing my finger or moving it) that would normally cancel the gesture, my app crashes. The reason given is that my popover is being dealloc'd while it is still showing, but I don't have anything that does that...

    BTW, the popover was working fine before I did the long touch.
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Are you retaining a reference to the popover? If not it's probably autoreleased and being dealloced as it should be
     
  6. Luke Redpath macrumors 6502a

    Joined:
    Nov 9, 2007
    Location:
    Colchester, UK
    #6
    We can only guess what the problem might be if you don't post any code...

    ...but it sounds like you're not keeping a reference to the popover around.

    As an aside, anybody working with popovers should know that you are only supposed to have one on screen at a time, and you may be interested in a small class I created called LRPopoverManager which simplifies the creation and presentation of popovers, while enforcing the one at a time rule. It's open-source and under the MIT license:

    http://github.com/lukeredpath/LRToolkit/blob/master/Classes/UIKit/LRPopoverManager.m
     
  7. ianprime0509 thread starter macrumors newbie

    Joined:
    Aug 31, 2010
    #7
    Thanks, all I had to do was retain it.
     
  8. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #8
    Remember to release it when you're done with it too :D
     

Share This Page