I have a UIBarButtonItem with UIButton as custom view.
The UIButton has a addTarget:action: on it. In the action I present a popover. I’m currently presenting from the sender.frame (the UIButton‘s Frame) I want to Present from the UIBarButtonItem instead.
How can I access the UIBarButtonItem from the UIButton?
If you have set your
UIButtonas thecustomViewof aUIBarButtonItem, or a child of the custom view, then you can walk up the view hierarchy from your button until you find theUIToolbarorUINavigationBarthat contains the button, then search the bar’s items for the one whose custom view is the button (or an ancestor of the button).Here’s my completely untested code for doing that. You would call
[[self class] barButtonItemForView:myButton]to get the item containing your button.