UINavigationBar 中的后退按钮隐藏问题
当我使用此: [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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这非常有效!
This works perfectly!
刚用过这个,就可以了。
Just used this and it works.
设置 self.navigationItem.backBarButtonItem = nil;
Set
self.navigationItem.backBarButtonItem = nil;
您遇到的问题是因为您没有更改导航栏的组成,只是隐藏了其中的一部分。当您设置按钮的隐藏值时,您只是在隐藏它,而不是删除它。它仍然会占用空间。要解决您的问题,您需要删除该按钮,然后当您希望用户能够导航离开时,只需重新添加按钮即可。
但实际上,如果您遇到这样的显示问题,您应该重新考虑导航栏 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.
您设置的属性指的是当“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.