In one app I work on, I have to put many (more than 5) toolbarItems on the toolbar of a UINavigationController, and need to replace one of the toolbar items when user taps it.
For making the code less clogging in -application:didFinishLaunchingWithOptions, I set up navigation controller in storyboard (OK, maybe it’s evil..) instead of programmatically. The toolbars displays all right. The only problem is I cannot grab toolbarItems in code:
NSMutableArray *toolbarItems = [[[self navigationController] toolbarItems] mutableCopy];
toolbarItems is always nil. Thus I cannot get my hands on one of the toolbarItems and change it as I intend to.
Is it normal or I am missing something obvious?
OK, I just fix it.. I should call
[self toolbarItems]instead of[[self navigationController] toolbarItems]. Hope this post could help others.