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.
Initialize your UIBarButtonItem like this:
_smay = [[UIBarButtonItem alloc] initWithTitle:@"Your Title"
style:UIBarButtonItemStyleBordered
target:self action:@selector(yourMethod)];
self.navigationItem.rightBarButtonItem = _smay;
Then, if you want to change the title somewhere else in your code:
[_smay setTitle:@"Your Other Title"];
IOS 8 and higher
UIBarButtonItemStyleBordered is deprecated, so use the below.
[[UIBarButtonItem alloc] initWithTitle:@"Your Title"
style:UIBarButtonItemStylePlain
target:self action:@selector(yourMethod)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With