简体   繁体   中英

Unable to set back button title ios

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM