设置模态视图控制器工具栏的项目
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终没有更改工具栏中的按钮,而是在 Interface Builder 中添加了一个按钮并更改了背景图像:
如果您确实需要更改按钮,您可能需要创建所有按钮并将它们公开在 ViewController 上,使用
setHidden
隐藏/显示它们。Rather than changing the buttons in the toolbar, I eventually just added a button in Interface Builder and changed the background image:
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.