UINavigationBar 中的后退按钮隐藏问题

发布于 2024-11-27 21:52:58 字数 501 浏览 7 评论 0原文

当我使用此: [self.navigationItem setHidesBackButton:YESanimated:NO]; 隐藏导航栏中的后退按钮时,我的标题不会居中。打印出来就像按钮仍然在那里一样。

有谁知道为什么会发生这种情况以及如何解决它?

编辑:

我的程序是这样的:我的 rootViewController 是一个导航控制器,我将其设置为隐藏导航栏。然后我推送到另一个 UIViewController,它使导航栏再次出现,但使后退按钮消失。

我尝试了设置 self.navigationItem.backBarButtonItem = nil;,但它并没有使后退按钮消失。

以下是一些图片供参考:

带后退按钮的图片 无图片

When I use this: [self.navigationItem setHidesBackButton:YES animated:NO]; to hide the back button in my navigationBar, my title doesn't get centered. It prints like the button is still there.

does anyone know why this happens, and how to fix it?

EDIT:

My program is like so: my rootViewController is a navigation controller, and I set that so the navigation bar is hidden. Then I push to another UIViewController, which I make the navigation bar appear again, but make the back button disappear.

I tried the setting self.navigationItem.backBarButtonItem = nil;, but it didn't make the backbutton disappear.

Here's some pictures for reference:

Picture with back button
Picture without

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

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

发布评论

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

评论(5

千秋岁 2024-12-04 21:52:59
viewController.navigationItem.hidesBackButton = YES;

这非常有效!

viewController.navigationItem.hidesBackButton = YES;

This works perfectly!

七婞 2024-12-04 21:52:59

刚用过这个,就可以了。

[self.navigationItem setHidesBackButton:YES animated:NO];
self.navigationItem.titleView.center = self.navigationController.navigationBar.center;

Just used this and it works.

[self.navigationItem setHidesBackButton:YES animated:NO];
self.navigationItem.titleView.center = self.navigationController.navigationBar.center;
往昔成烟 2024-12-04 21:52:59

设置 self.navigationItem.backBarButtonItem = nil;

Set self.navigationItem.backBarButtonItem = nil;

节枝 2024-12-04 21:52:59

您遇到的问题是因为您没有更改导航栏的组成,只是隐藏了其中的一部分。当您设置按钮的隐藏值时,您只是在隐藏它,而不是删除它。它仍然会占用空间。要解决您的问题,您需要删除该按钮,然后当您希望用户能够导航离开时,只需重新添加按钮即可。

但实际上,如果您遇到这样的显示问题,您应该重新考虑导航栏 UI 设计,并尝试提出更有效的按钮标题。

The problem you are running into is because you are not changing your navigation bar's composition, you are just hiding part of it. When you set the hidden value of your button, you are doing just that, hiding it, not removing it. It will still take up space. To solve your problem you need to remove the button, then when you want the use to be able to navigate away, just add your button back.

Realistically though, if you are having display issues like this you should reconsider your navigation bar UI design and try to come up with a more effective button title.

英雄似剑 2024-12-04 21:52:59

您设置的属性指的是当“self”是导航控制器堆栈中的“后退”项时如何表示。我假设您在“工作日历”视图控制器中设置它,除非该控制器有更多的子视图,否则它不会工作。

尝试将导航栏 leftButtonItem 属性设置为 nil。

The property you are setting refers to how the "self" is represented when it is the "back" item in the navigation controller stack. I assume you are setting this in your "work calendar" view controller, it won't work unless that controller has further child views.

Try setting the navigation bar leftButtonItem property to nil instead.

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