Setting Toolbar Items of UINavigationController

cocoa-touch, interface-builder, uinavigationcontroller, uitoolbar, uitoolbaritem

Solution

It's a perfectly acceptable way of doing it, but do bear in mind that loading xib files is quite expensive on the iPhone, and it may well be faster to create the toolbar items programatically in your viewDidLoad method.

Problem

In iPhone OS 3.0, you can set the toolbar items of a UINavigationController using the `setToolbarItems:animated:` method. However, this requires you pass in an array of UIToolbarItems. While I could programmatically create these toolbar items, I'd rather create them in Interface Builder if possible. With this in mind, I have created a UIToolbar in "MyGreatViewController.xib" and have populated it with the wanted toolbar items. Then, in "MyGreatViewController.m", I get the items from the toolbar and pass them to `setToolbarItems:animated:`: ``` - (void)viewDidLoad { [super viewDidLoad]; [self setToolbarItems: [toolbar items]]; } ``` ...where `toolbar` is an IBOutlet referring to the UIToolbar. Is this a good approach? Is there a better way to accomplish this? Should I just create the items programmatically?

Original source