Reputation: 851
I added (or show) a Toolbar on the Navigation Controller with the "Show Toolbar" checkbox in the Attributes Inspector in Xcode 6.2.
Because
The custom toolbar associated with the navigation controller. (read-only)
I'm using
self.navigationController?.setToolbarItems(items, animated: true)
to add my items to the toolbar (items is a NSArray
) but the toolbar doesn't show up any items so far. To test a few things I tried to add a single UIBarButtomItem
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 UIViewController
.
I already debugged my code to find out if there is a nil
around but neither the UIBarButtonItem
nor the navigationController
are nil
.
Upvotes: 2
Views: 765
Reputation: 10160
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.
Upvotes: 4