UINavigationController toolbarItems not getting set


#1

I am trying to add toolBarItems in BNRItemsViewController in viewDidLoad, below is the code

UIBarButtonItem *bbiItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(pickItem)];
// Create Array initialized with bar button item
NSArray *toolBarItems = [[NSArray alloc] initWithObjects:bbiItem, nil];

// toolBarItems are automatically picked and set by the navigation controller

[self setToolbarItems:toolBarItems animated:YES];

When I try state restoration for BNRItemsViewController, the UINavigationController toolBar is not set, running normally displays it, I have tried debugging it and what I understand is that the view of the BNRItemsViewController gets loaded after the UINavigationController has been created, that’s the reason it does not pick the toolBarItems set in itemViewController, there is no control in explicitly pushing the view controller for state restoration, the current code in the book does not address this I think, is there a way to update in ViewWillAppear?


#2

after a lot of debugging I found the solution, during state restoration when the app attempts to recreate the view hierarchy the view of BNRItemsViewController gets loaded before being pushed into the UINavigationController, so you are not able to access the NavigationController in ViewDidLoad, also by default the custom toolbar of the UINavigationController is hidden by default, so you got to unhide it in viewWillAppear where you have access to the navigation controller pointer through the view controller.