问题描述
我正在使用XCode 4和故事板我正在创建的应用程序,但是我无法直观地修改UIToolbar。
I'm using XCode 4 and storyboarding an application I'm creating, however I cannot visually modify the UIToolbar.
我正在尝试修改一个UIToolbar在UITableViewController中 - 但是我必须将UIToolbar放在正确的层次结构之外,以便能够直观地修改它。我已经尝试将它放在视图控制器区域,但这并没有显示出来。
I'm attempting to modify a UIToolbar that is inside of a UITableViewController - however I have to place the UIToolbar out of the correct hierarchy in order to be able to modify it visually. I've tried placing it onto the view controller area but that does not make it show up.
有一次,我能够让它显示在下方,因为它是自己的对象,但是我无法重新创建它。
At one point I was able to make it appear below, as it's own object however I was not able to recreate that.
我曾经能够让它看起来像这样
Once I was able to get it to look like this
推荐答案
您的 UITableViewController
位于 UINavigationController
中,已有自己的 UIToolbar
- 您无需将新的拖动到视图层次结构中。 Interface Builder可以在检查器面板中的模拟指标下为您模拟工具栏。
Your UITableViewController
is inside a UINavigationController
, which already has its own UIToolbar
—you don't need to drag a new one into your view hierarchy. Interface Builder can simulate the toolbar for you under "Simulated Metrics" in the inspector panel.
模拟工具栏可见后,只需拖动 UIBarButtonItem
进入它。如果您需要比按钮或间隔更复杂的东西,请使用带有自定义视图的自定义项目。
Once the simulated toolbar is visible, simply drag UIBarButtonItem
s into it. Use a custom item with a custom view if you need anything more complicated than a button or spacer.
如果您需要工具栏项目需要是动态的,您可以维护通过 IBOutlet
引用,而不必在您的视图中显示它们。然后设置 UITableViewController
的 toolbarItems
属性或调用 -setToolbarItems:animated:
在运行时显示相应的项目。
If you need your toolbar items need to be dynamic, you can maintain a reference via IBOutlet
s without necessarily having them in your view. Then set your UITableViewController
's toolbarItems
property or call -setToolbarItems:animated:
at runtime to display the appropriate items.
参见Apple的。
See Apple's UINavigationController
Class Reference: Displaying a Toolbar.
这篇关于从xcode故事板中可视化修改UIToolbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!