I\'m trying to add a custom label in my UINavigationController\'s toolbar. I followed the top answer for this question but it doesn\'t seem to work for me and I don\'t know
I know this question is answered and old, but I had the same experience, and found something interesting. My code needs to display (in the toolbar) a button sometimes, and a label some others, depending on the state of the program. If I create a UILabel object in my controller class, and reuse it in calls to
UIBarButtonItem *myItem = [[UIBarButtonItem alloc] initWithCustomView: _myUILabel];
[self setToolbarItems: [NSArray arrayWithObject: myItem]];
[myItem release];
every time I need to switch from the button to the label, then the label will not show up (Actually it shows up the first time, and after switching back and forth once, it stops showing up). I spent hours on the issue, and if it's not for the fact I'm bald, I would probably pulled all my hair out in despair anyway. I verified all my retain counts are fine. My saved label is good and valid.
I found that if I create a new label every time I need to show it in the toolbar, then the problem goes away. There is definitely an issue in the handling of a UILabel inside setToolbarItems. So, my advice, create a new label, set the text, etc., wrap it in a UIToolBarItem, and set your toolbar items again.
It's not ideal, it exercises alloc and release more, but it works. I hope this will help someone out there.