将右侧 Bar ButtonItem 从“保存”更改为到“完成”

发布于 2024-12-28 11:15:12 字数 293 浏览 0 评论 0原文

我有一个带有右侧 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 技术交流群。

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

发布评论

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

评论(2

绅刃 2025-01-04 11:15:12

马特是对的 - 有两个按钮并根据需要将它们换入/换出。尽管我希望您可以跟踪一个按钮并更改标题;当您还希望执行两项不同的操作时,为什么要这样做?

 saveBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(save:)];

 doneBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(done:)];

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?

 saveBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(save:)];

 doneBarButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(done:)];
愁杀 2025-01-04 11:15:12

我通常在这里做的是创建另一个标题为“完成”的 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 call setRightBarButtonItem:animated: on the UINavigationItem 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.

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