将右侧 Bar ButtonItem 从“保存”更改为到“完成”
我有一个带有右侧 BarButtonItem 的 NavigationItem 及其标识符 - 最初 - “保存”以保存我在视图上创建的实体。
在我看来,我使用 DatePicker。如果此 DatePicker 可见,则“保存”按钮不应是“保存”按钮,而是“完成”按钮。如果 DatePicker 不可见,“完成”按钮应再次更改为“保存”。
我理解 Interface Builder 中的标识符,就像包含本地化一样。所以我想,我不能只改变标题,对吧?
您能告诉我如何将按钮从“保存”更改为“完成”或者如何执行其他操作吗?
i have a NavigationItem with a right BarButtonItem and it's Identifier - initially - 'Save' to save entities i create on the view.
In my view i use a DatePicker. If this DatePicker is visible, the 'Save' Button should not be a 'Save' Button but a 'Done' Button. If the DatePicker is not visible, the 'Done' Button should change to 'Save' again.
I understand the identifier in Interface Builder like that localization is included. So I think, i can't just change the Title, right?
Can you tell me how to change the button from 'Save' to 'Done' or how i do it otherwise?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
马特是对的 - 有两个按钮并根据需要将它们换入/换出。尽管我希望您可以跟踪一个按钮并更改标题;当您还希望执行两项不同的操作时,为什么要这样做?
matt is right - have two buttons and swap them in / out as needed. Although I expect you could keep track of one button and change the title; why would you do that when you also have two different actions that you wish to perform?
我通常在这里做的是创建另一个标题为“完成”的
UIBarButtonItem
实例,并将其与普通的“保存”按钮一起保存为视图控制器中的实例变量。然后,当需要显示“完成”按钮时,我会在UINavigationItem
上调用setRightBarButtonItem:animated:
来更改按钮,并同样将其设置回“保存” ' 按钮(需要时)。我认为这通常比仅仅更改标题更好,因为它们是不同的操作,因此将它们连接到不同的操作方法更有意义。
What I would normally do here is to create another
UIBarButtonItem
instance with title 'Done' and save it along with the normal 'Save' button as instance variables in my view controller. Then when the 'Done' button needs to be shown I would callsetRightBarButtonItem:animated:
on theUINavigationItem
to change the button and the same to set it back to the 'Save' button when required.I think that's generally better than just changing the title as they are distinct actions so it makes more sense for them to be wired up to different action methods.