gpt4 book ai didi

ios - 按下后退按钮时,上一个屏幕上的导航标题消失

转载 作者:可可西里 更新时间:2023-11-01 03:33:00 28 4
gpt4 key购买 nike

我对导航栏标题有疑问。我有 2 个屏幕,当我单击屏幕 2 上的后退按钮时,它将返回到屏幕 1,但屏幕 1 的标题消失了。这是我的代码片段

屏幕1.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 的标题出现以下技巧:

  1. viewwillappear 方法上设置标题

    - (void)viewWillAppear:(BOOL)animated{self.title = @"tes";}
  2. viewdidappear 方法上设置标题

     - (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];
}

最佳答案

这解决了我的问题:

override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated: animated)
self.navigationItem.title="Title text"
}

关于ios - 按下后退按钮时,上一个屏幕上的导航标题消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24506213/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com