简体   繁体   English

无法设置后退按钮标题iOS

[英]Unable to set back button title ios

I am new to iOS, 我是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. 我想全局设置UINavigationBar上所有后退按钮的空文本,因为我有多个UINavigationBar,因此可以尝试使用类别。

Here is my code: 这是我的代码:

UINavigationItem+BackButton.h UINavigationItem + BackButton.h

@interface UINavigationItem (BackButton)
- (void)removeBackText;
@end

UINavigationItem+BackButton.m 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 在我的一个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 更改removeBackText方法

- (void)removeBackText
{
    self.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];    
}

Here initWithTitle:@"" not initWithTitle:@"Bc" 这里的initWithTitle:@""不是initWithTitle:@"Bc"

And also you need to change your viewWillAppear method to add back barButton on navigation bar like below. 另外,您还需要更改viewWillAppear方法,以在导航栏上添加backbarButton,如下所示。

self.navigationItem.backBarButtonItem = myBackButton;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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