title: How can you add a UIGestureRecognizer to a UIBarButtonItem as in the common undo/redo UIPopoverController scheme on iPad apps?
body: <p><strong>Problem</strong></p>
  
  <p>In my iPad app, I cannot attach a popover to a button bar item <em>only</em> after press-and-hold events.  But this seems to be standard for undo/redo.  How do other apps do this? </p>
  
  <p><strong>Background</strong></p>
  
  <p>I have an undo button (UIBarButtonSystemItemUndo) in the toolbar of my UIKit (iPad) app.  When I press the undo button, it fires it's action which is undo:, and that executes correctly.  </p>
  
  <p>However, the "standard UE convention" for undo/redo on iPad is that pressing undo executes an undo but <em>pressing and holding</em> the button reveals a popover controller where the user selected either "undo" or "redo" until the controller is dismissed.</p>
  
  <p>The normal way to attach a popover controller is with presentPopoverFromBarButtonItem:, and I can configure this easily enough.  To get this to show only after press-and-hold we have to set a view to respond to "long press" gesture events as in this snippet:</p>
  
  <pre><code>UILongPressGestureRecognizer *longPressOnUndoGesture = [[UILongPressGestureRecognizer alloc] 
         initWithTarget:self 
                 action:@selector(handleLongPressOnUndoGesture:)];
  //Broken because there is no customView in a UIBarButtonSystemItemUndo item
  [self.undoButtonItem.customView addGestureRecognizer:longPressOnUndoGesture];
  [longPressOnUndoGesture release];
  </code></pre>
  
  <p>With this, after a press-and-hold on the view the method handleLongPressOnUndoGesture: will get called, and within this method I will configure and display the popover for undo/redo.  So far, so good.</p>
  
  <p>The problem with this is that there <em>is no view</em> to attach to.  self.undoButtonItem is a UIButtonBarItem, not a view.</p>
  
  <p><strong>Possible solutions</strong></p>
  
  <p>1) [The ideal] <em>Attach the gesture recognizer to the button bar item</em>.  It is possible to attach a gesture recognizer to a view, but UIButtonBarItem is not a view.  It does have a property for .customView, but that property is nil when the buttonbaritem is  a standard system type (in this case it is).</p>
  
  <p>2) <em>Use another view</em>.  I could use the UIToolbar but that would require some weird hit-testing and be an all around hack, if even possible in the first place.  There is no other alternative view to use that I can think of.  </p>
  
  <p>3) <em>Use the customView property</em>.  Standard types like UIBarButtonSystemItemUndo have no customView (it is nil).  Setting the customView will erase the standard contents which it needs to have.  This would amount to re-implementing all the look and function of UIBarButtonSystemItemUndo, again if even possible to do.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I attach a gesture recognizer to this "button"?  More specifically, how can I implement the standard press-and-hold-to-show-redo-popover in an iPad app?</p>
  
  <p>Ideas?  Thank you very much, especially if someone actually has this working in their app (I'm thinking of you, omni) and wants to share...</p>