如何隐藏 UIBarButtonItem?
我在 IB 中创建了一个简单的 UI,它由一个 UINavigationBar
和一个我拖放到右侧的 UIBarButtonItem
组成。
我试图将此按钮设置为隐藏某些时间,但遇到了一些问题。
到目前为止,我已经尝试使用:
self.NavigationItem.rightBarButton = nil;
...这对我不起作用。我还尝试创建和 IBOutlet
并将其链接到按钮,但是我也遇到了问题。我认为它应该非常简单,也许我把它弄得太复杂了,但在这一点上我很困惑!
请问有人可以帮我吗?
I have created a simple UI in IB, this consists of a UINavigationBar
and a UIBarButtonItem
that I dragged and dropped on the right hand side.
I am trying to set this button to be hidden a certain times but I am having some problems.
So far I have tried using:
self.NavigationItem.rightBarButton = nil;
...which didn't work for me. I have also tried creating and IBOutlet
and linking it to the button however I'm having problems with this too. I think it should be pretty simple and maybe I'm over-complicating it, but at this point I'm pretty stumped!
Please can someone help me out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
UINavigationItem
没有rightBarButton
属性。尝试rightBarButtonItem
代替(或[self.navigationItem setRightBarButtonItem:nil 动画:NO];
):UINavigationItem
doesnt have arightBarButton
property. TryrightBarButtonItem
instead (or[self.navigationItem setRightBarButtonItem:nil animated:NO];
):只需重置按钮
更多信息:http://developer.apple.com/iphone/library/documentation/uikit/reference/UIToolbar_Class/Reference/Reference.html#//apple_ref/occ/instm/UIToolbar/setItems%3aanimated%3a< /a>
您可以使用 items 属性获取当前项目,然后删除您不想显示的项目并传入新的 NSArray。
Just reset the buttons
More info here: http://developer.apple.com/iphone/library/documentation/uikit/reference/UIToolbar_Class/Reference/Reference.html#//apple_ref/occ/instm/UIToolbar/setItems%3aanimated%3a
You can get the current items using the items property, then just remove the one you don't want to show and pass in the new NSArray.
您还可以添加 UIButton 作为 UIBarButtonItem 的 customView。然后在customView(UIButton)上设置隐藏属性
You can also add a UIButton as the UIBarButtonItem's customView. Then set the hidden property on the customView (UIButton)
您可以将其设置为禁用时清除文本,而不是删除栏按钮项目并销毁按钮及其附加的故事板转场。
然后,当您想要隐藏栏按钮项目时,您可以这样做:
它很蹩脚,没有隐藏属性,但这提供了相同的结果。
Rather than deleting the bar button item and destroying the button and it's attached storyboard segue, you can just set it to clear text when it's disabled.
Then when ever you want the bar button item hidden, you can just do:
It's lame there's no hidden property but this offers the same result.
实际上,您可以创建对所需 UIBarButtonItem 的 IBOutlet 引用,并且在需要时只需执行以下操作:
Actually, you can just create an IBOutlet reference to the desired UIBarButtonItem and when needed just do as follow:
最简单的解决方案:只需将 BarButtonItem 的标识符更改为自定义即可。
The simplest solution: Just change the BarButtonItem's identifier to custom.