设置模态视图控制器工具栏的项目

发布于 2024-12-25 18:25:56 字数 783 浏览 1 评论 0原文

我有一个 ViewController,我正在使用模式转换。它有一个工具栏,我在界面生成器中添加了五个项目(包括空格)。我试图从代码中设置按钮,因此当编辑此模式 ViewController 中的表视图时,显示“锁定”按钮,当不编辑时,显示“解锁”按钮。

尽管我尝试了,按钮并没有改变。

我已经尝试过(1 月 13 日更新):

[self setToolbarItems:...animated:true]; // failed
[self.navigationItem setLeftBarButtonItems:... animated:true]; // also failed, though self.navigationItem is not null
[self.parentViewController setToolbarItems:... animated:true];
[self.navigationController setToolbarItems:... animated:true];
[self.tabBarController setToolbarItems:... animated:true];
[self.navigationItem setLeftBarButtonItems:... animated:true];
[self.navigationController.toolbar setItems:

全部失败。

该 ViewController 从另一个 VC(非模态)中显示,该 VC 被推送到 NavigationController 上。

我在这件事上做错了吗?

I have a ViewController which I'm using a modal transition for. It has a toolbar and I've added five items (including space) in interface builder. I'm trying to set the buttons from code, so when the table view in this modal ViewController is being edited, show a 'lock' button, when it's not editing, show an 'unlock' button.

Despite my attempts, the buttons aren't changing.

I've tried (updated 13th Jan):

[self setToolbarItems:...animated:true]; // failed
[self.navigationItem setLeftBarButtonItems:... animated:true]; // also failed, though self.navigationItem is not null
[self.parentViewController setToolbarItems:... animated:true];
[self.navigationController setToolbarItems:... animated:true];
[self.tabBarController setToolbarItems:... animated:true];
[self.navigationItem setLeftBarButtonItems:... animated:true];
[self.navigationController.toolbar setItems:

All of which failed.

This ViewController is shown from another VC (non modal), which is pushed onto a NavigationController.

Am I going about this wrong?

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

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

发布评论

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

评论(1

眼眸 2025-01-01 18:25:56

我最终没有更改工具栏中的按钮,而是在 Interface Builder 中添加了一个按钮并更改了背景图像:

btnLock.image = [UIImage imageNamed:@"lock_open_white_30.png"];

如果您确实需要更改按钮,您可能需要创建所有按钮并将它们公开在 ViewController 上,使用 setHidden 隐藏/显示它们。

Rather than changing the buttons in the toolbar, I eventually just added a button in Interface Builder and changed the background image:

btnLock.image = [UIImage imageNamed:@"lock_open_white_30.png"];

If you really did need to change the buttons, you'd probably need to create all the buttons and expose them on your ViewController, the use setHidden to hide/show them.

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