- 1 year ago 106
Swift Question

Navigationcontroller toolbar doesn't show UIBarButtonItem

I added (or show) a Toolbar on the Navigation Controller with the "Show Toolbar" checkbox in the Attributes Inspector in Xcode 6.2.


The custom toolbar associated with the navigation controller.

I'm using
self.navigationController?.setToolbarItems(items, animated: true)

to add my items to the toolbar (items is a
) but the toolbar doesn't show up any items so far. To test a few things I tried to add a single
which is created this way:

testBarButtonItem = UIBarButtonItem(title: "testTitle", style: .Plain, target: nil, action: nil)

The code is inside the
override func viewDidLoad()
of a

I already debugged my code to find out if there is a
around but neither the
nor the

Answer Source

Use self.toolbarItems of the viewcontroller itself. Do not manipulate the toolbar of the navigation controller directly.

(I've not used self.toolbarItems in a while so im not 100% positive, but I guess it works like for self.navigationItem.leftBarButtonItems and .rightBarButtonItems)

EDIT: Or there should also be a method setToolbarItems:animated (on the UIViewController, not the UINavigationController) which is perhaps better.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download