問題描述
我正在使用 XCode 4 和故事板我正在創建的應用程序,但是我無法直觀地修改 UIToolbar.
I'm using XCode 4 and storyboarding an application I'm creating, however I cannot visually modify the UIToolbar.
我正在嘗試修改 UITableViewController 內部的 UIToolbar - 但是我必須將 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 可以在 Inspector 面板的Simulated Metrics"下為您模擬工具欄.
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 的 UINavigationController
類參考:顯示工具欄.
See Apple's UINavigationController
Class Reference: Displaying a Toolbar.
這篇關于從 xcode 故事板可視化修改 UIToolbar的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!