How can you add a UIGestureRecognizer to a UIBarButtonItem as in the common undo/redo UIPopoverController scheme on iPad apps?

Note: this no longer works as of iOS 11

In lieu of that mess with trying to find the UIBarButtonItem’s view in the toolbar’s subview list, you can also try this, once the item is added to the toolbar:

[barButtonItem valueForKey:@"view"];

This uses the Key-Value Coding framework to access the UIBarButtonItem’s private _view variable, where it keeps the view it created.

Granted, I don’t know where this falls in terms of Apple’s private API thing (this is public method used to access a private variable of a public class – not like accessing private frameworks to make fancy Apple-only effects or anything), but it does work, and rather painlessly.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)