Here's another way to do it.
In your parent view controller, implement the following method:
- (void) setBackBarButtonItemTitle:(NSString *)newTitle {
self.navigationItem.backBarButtonItem.title = newTitle;
}
In your child view controller, when you want to change the title, this will work:
NSArray *viewControllerArray = [self.navigationController viewControllers];
int parentViewControllerIndex = [viewControllerArray count] - 2;
[[viewControllerArray objectAtIndex:parentViewControllerIndex] setBackBarButtonItemTitle:@"New Title"];
I was never able to get the parentViewController
property to work:
[(ParentViewController *)(self.navigationController.parentViewController) setBackBarButtonItemTitle:@"New Title"];
I don't know if that's a bug or I'm not using it properly. But grabbing the second-to-last view controller in the viewControllers
array points to the parent view controller, and I can call parent methods correctly with that reference.