Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ianprime0509

macrumors newbie
Original poster
Aug 31, 2010
10
0
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
 
Just check the view again the UIButton object. Remember that a UIButton is a subclass of UIView. You only need one gesture recognizer.
 
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.
 
Are you retaining a reference to the popover? If not it's probably autoreleased and being dealloced as it should be
 
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.

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.