gpt4 book ai didi

ios - 在没有UINavigationController的情况下向navigationItem添加backBarButtonItem?

转载 作者:行者123 更新时间:2023-11-29 04:41:59 26 4
gpt4 key购买 nike

我有一个UIViewController,我在InterfaceBuilder中添加了一个navigationItem来查看标题,我发现我无法将backBarButtonItem拖动到navigationItem,只能添加leftBarButtonItem和rightBarButtonItem。因此,我尝试将 backBarButtonItem 添加到 Controller 代码中的 navigationItem 元素:

- (void)viewWillAppear:(BOOL)animated {
UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
self.myNavigationItem.backBarButtonItem = _backButton;
[_backButton release];
}

但是 View 上仍然没有 backBarButtonItem?如何解决?

最佳答案

您必须实际设置 leftBarButtonItem,而不是 backBarButtonItem,并且只有在设置 self.hidesBackBarButtonItem 后才可以,如下所示:

- (void)viewWillAppear:(BOOL)animated {
 UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back"   style:UIBarButtonItemStyleDone target:nil action:nil];
   self.navigationItem.hidesBackButtonItem = YES;
self.myNavigationItem.leftBarButtonItem = _backButton;
  [_backButton release];
}

关于ios - 在没有UINavigationController的情况下向navigationItem添加backBarButtonItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10256651/

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