does anyone knows how to get the text content of a backBarButtonItem when using a UINavigationController ? It's the name of the previous view but I'd like to get it in the next view.
Thanks!
does anyone knows how to get the text content of a backBarButtonItem when using a UINavigationController ? It's the name of the previous view but I'd like to get it in the next view.
Thanks!
Here's one way to get the title of the previous viewController in the navigation controller viewController stack:
((UIViewController*)[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2]).title
You need to create a UIBarButtonItem using:
- (id)initWithTitle:(NSString *)title style:(UIBarButtonItemStyle)style target:(id)target action:(SEL)action
Then you attach the target to your method and you can pop the controller in your method.
It's property of UIBarItem
: backBarButtonItem.title
UIViewController* backController = (UIViewController*)[self.navigationController.viewControllers objectAtIndex:[self.navigationController.viewControllers count] - 2];
NSString* backTitle = backController.navigationItem.title;