Search code examples
iosobjective-ccocoa-touchuikituibaritem

UIBarItem - access customView as method/property


When creating a UIBarButtonItem with a custom view, is it possible to access that custom view again, without having to keep a pointer externally? Eg:

barButtonItem.customView

There does not appear to be such a property or method. Once you pass it in via the init, it seems to be an internal concern to that class.


Solution

  • Perhaps you have some confusion on your variable. You can assign a custom view to a UIBarButtonItem and not to a UIBarItem.

    If indeed you do mean UIBarButtonItem, using a custom View dramatically changes how it performs. If you use a custom view, the bar button item will no longer call the action method of its target to for any user interactions. It instead expects the custom view to handle user interactions.

    So I think it would make sense to keep a reference to this custom view around so that you can handle any user interactions through it.