我有一个导航栏标题的问题。我有两个屏幕,当我在第二个屏幕点击返回按钮时,它会返回到第一个屏幕,但是第一个屏幕的标题消失了。这是我的代码片段:
screen1.m
我已经尝试了几个技巧来让屏幕1的标题出现,具体如下:
这里是我如何移动到下一个屏幕的方式。
screen1.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"title 1";
....
屏幕2 .m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = self.stringTitle;
// change the back button and add an event handler
self.navigationItem.hidesBackButton = YES;
//set custom image to button if needed
UIImage *backButtonImage = [UIImage imageNamed:@"btn_back.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:backButtonImage forState:UIControlStateNormal];
button.frame = CGRectMake(-12, 2, backButtonImage.size.width, backButtonImage.size.height);
[button addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, backButtonImage.size.width-15, backButtonImage.size.height)];
[backButtonView addSubview:button];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
self.navigationItem.leftBarButtonItem = customBarItem;
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
....
}
- (void) backAction
{
[self.navigationController popViewControllerAnimated:YES];
}
我已经尝试了几个技巧来让屏幕1的标题出现,具体如下:
set title on
viewwillappear
method- (void)viewWillAppear:(BOOL)animated{self.title = @"tes";}
set title on
viewdidappear
method- (void)viewDidAppear:(BOOL)animated{ self.navigationController.navigationBar.topItem.title = @"YourTitle"; self.title = @"tes"; }
这里是我如何移动到下一个屏幕的方式。
- (IBAction)btGenerateTokenAction:(id)sender {
SofttokenResultController *controller = [[SofttokenResultController alloc] initWithNibName:@"SofttokenResultController" bundle:nil];
controller.navigationController.navigationBar.backItem.title = @"Kembali";
[ViewLoadingUtil animateToNextView:controller from:self :@""];
}
+ (void) animateToNextView:(UIViewController *)controller from:(UIViewController *)fromController :(NSString *)navTitle{
NSLog(@"animateToNextView called");
[fromController.navigationController pushViewController:controller animated:YES];
}
self.navigationItem.title
。 - ChintaN -Maddy- Ramani