I want to change UIBarButtonItem
's title
.
But this code is not working.
- (void)viewDidLoad {
...
[self smay];
}
- (void)smay {
...
AppDelegate *apd = (AppDelegate*)[[UIApplication sharedApplication]delegate];
NSString *SmayUse = [NSString stringWithFormat:@"%d月%d日",
apd.newyear,apd.newmonth];
[_smay setTitle:SmayUse]
}
I don't know how to solve this problem.
Please tell me a way to solve this problem.
item.title = @"new title"
should work.if u want to change the title of navigation bar programmatically means
You have to make sure the button is initialized. If it is part of a .xib file, make sure you have it linked up with your
@property
that has also anIBOutlet
associated with it. Otherwise you need to initialize it programatically. Also, you should use the methodsetTitle:forState:
.Initialize your UIBarButtonItem like this:
Then, if you want to change the title somewhere else in your code:
IOS 8 and higher
UIBarButtonItemStyleBordered is deprecated, so use the below.