I am new to iOS,
I want to set empty text to all back button on UINavigationBar globally because i have multiple UINavigationBar so thought to try using category.
Here is my code:
UINavigationItem+BackButton.h
@interface UINavigationItem (BackButton)
- (void)removeBackText;
@end
UINavigationItem+BackButton.m
@implementation UINavigationItem (BackButton)
- (void)removeBackText
{
self.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Bc" style:UIBarButtonItemStylePlain target:nil action:nil];
}
@end
In one of my ViewController
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController.navigationItem removeBackText];
}
I have tried this but its not working. Can any help help where i am doing mistake?
Thank you in advance
Change in your removeBackText
method
- (void)removeBackText
{
self.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
}
Here initWithTitle:@""
not initWithTitle:@"Bc"
And also you need to change your viewWillAppear
method to add back barButton on navigation bar like below.
self.navigationItem.backBarButtonItem = myBackButton;