I have a UIBarButtonItem which I want to create once as it appears on many views.
Within a tabbar on different UINavigationBar of the viewControllers I add the same button instance:
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:
self.aButtonItem,
appDelegate.aSingleton.singleButtonItem,
nil]
When I switch between views, the single instance button is only displayed the first time. There is an empty space and you can even click on the position where the button used to be and the action gets called correctly.
It is only that the button is not displayed anymore.
Is this a documented “feature”?
Why am I doing this?
I change the button to be selected _singleButtonItem.selected=YES to show the user a notification (like a badge, but less intrusively). Therefore I would like to have a single instance.
A single object cannot be at multiple places. You would need to created multiple ones. However you can store the badge value somewhere and show it on every button to meet your needs.
Logically, a UIView can have only one parent view. So if you add the same child view to another, it would be removed from the first parent view and added as a child to the second parent view.