iPhone - UINavigationItem - 隐藏后退按钮

发布于 2024-10-06 22:57:37 字数 1483 浏览 6 评论 0原文

我很困惑。我正在使用 UINavigationController,在一个视图上我试图隐藏后退按钮。但是当我这样做时,它也会隐藏下一级视图上的后退按钮。

- (void)viewWillAppear:(BOOL)animated 中,我有:

[self.navigationItem setHidesBackButton:YES animated:NO];

- (void)viewWillDisappear:(BOOL)animated 中,我有:

[self.navigationItem setHidesBackButton:NO animated:NO];

这只是使后退按钮出现就在它离开之前(这似乎是该调用的正确功能)。因此,我厌倦了放入

[self.navigationItem setHidesBackButton:NO animated:NO];

下一个视图的 - (void)viewWillAppear:(BOOL)animated ,但这仍然不起作用。

这有点令人困惑,因为 self.navigationItem.backBarButtonItem 是该视图的后退按钮的引用,当它是顶部视图正下方的视图时(ref)。但是 self.navigationItem.hidesBackbutton 是在顶视图时是否显示后退按钮(ref)。那么有人知道为什么它会隐藏下一个视图的后退按钮吗?

另一个奇怪的事情是,当我向下看另一个视图时它会起作用。为了更直观地表示,假设我有以下视图:

A > B > C > D

B 是我关心的视图。我想隐藏将转到 A 的后退按钮。当我这样做时,它也会隐藏 C 上的后退按钮。但如果我按下 D 按钮,后退按钮就会出现,然后一切都会按“应该”的方式运行。也就是说,我可以返回到 C,然后返回到 B。B 隐藏了后退按钮,如果我返回到 C,则后退按钮会按应有的方式显示。

有什么想法吗?

I'm stumped. I'm using a UINavigationController and on one view I'm trying to hide the back button. But when I do that it hides the back button on the next level of views also.

In - (void)viewWillAppear:(BOOL)animated I have:

[self.navigationItem setHidesBackButton:YES animated:NO];

And in - (void)viewWillDisappear:(BOOL)animated I have:

[self.navigationItem setHidesBackButton:NO animated:NO];

This just makes the back button appear just before it leaves (which seems like that is the correct functionality of that call). Therefore I tired to put

[self.navigationItem setHidesBackButton:NO animated:NO];

in - (void)viewWillAppear:(BOOL)animated of the next view, and that still doesn't work.

This is a little confusing since self.navigationItem.backBarButtonItem is a reference of what that view's back button will be when it is the view just under the top view (ref). But self.navigationItem.hidesBackbutton is whether the back button is shown when it is the top view (ref). So does anyone have any idea why it would hide the back button of the next view?

Another strange thing is it works when I go another view down. For a more visual representation, lets say I have the following views:

A > B > C > D

B is the view I'm concerned about. I want to hide the back button which would go to A. When I do that it hides the back button on C also. But if I do down to D, the back button shows up and then everything acts as it "should." That is, I can go back to C, then Back to B. B has it's back button hidden and if I go back into C the back button shows up like it should.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

茶花眉 2024-10-13 22:57:37

在处理 UINavigationController 时,似乎存在某种关于隐藏和显示后退按钮的错误。与您类似的问题是NavigationController的backButton不出现

我对此做了一些测试,虽然我没有解释,但这里有一些可能对您有帮助的建议。

  • 仅在 viewDidAppear: 中调用 setHidesBackButton:animated:,在 viewWillAppear:不调用
  • 不要使用 self.navigationItem.hidesBackButton 任何地方。

There seems to be some kind of bug regarding the hiding and showing of the back button when dealing with a UINavigationController. A similar problem to yours is backButton of NavigationController don't appear.

I did some testing regarding this and while I don't have an explanation here are some suggestions that might help you.

  • Only make calls to setHidesBackButton:animated: in viewDidAppear: and not in viewWillAppear:
  • Don't use self.navigationItem.hidesBackButton anywhere.
忆离笙 2024-10-13 22:57:37

为了解决这个愚蠢的错误,我根本没有实现 setHidesBackButton,但在 viewDidLoad 中我输入了以下内容:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];

To get by this stupid bug, I did not implement setHidesBackButton at all, but in viewDidLoad I put the following:

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];
萧瑟寒风 2024-10-13 22:57:37

我想您知道隐藏后退按钮并不会阻止用户单击它?

为了防止点击,你必须将其设置为零。

 self.navigationItem.leftBarButtomItem = nil;

然后您可以在“B”的 viewWillAppear 方法中创建一个新的后退按钮。

I guess you know that hiding the back button doesn't prevent a user from clicking on it?

To prevent a click, you have to set it as nil.

 self.navigationItem.leftBarButtomItem = nil;

Then you could create a new back button in "B"'s viewWillAppear method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文