Visually modifying a UIToolbar from xcode storyboard

前端 未结 3 1163
执笔经年
执笔经年 2020-12-06 03:25

I\'m using XCode 4 and storyboarding an application I\'m creating, however I cannot visually modify the UIToolbar.

I\'m attempting to modify a UIToolbar that is insi

相关标签:
3条回答
  • 2020-12-06 03:46

    UITableViewControllers only allow one view object, which of course is UITableView. UITableViews are not cooperative for subviewing and they usually push everything into footers or headers. Something like this isn't possible:

    -TableController
        -Table
            -Subview
            -Another subview
    

    UITableViewControllers are reduced to this:

    -TableViewController
        -Table
    

    So you will need to use a UIViewController and declare a UITableView in there. Heres the Hierarchy you should use then:

    - ViewController <Table's Delegate & Data Source>
        - View           
            -Table
            - Your UIToolbar
    

    In your ViewController.h declare IBOutlet UITableView and connect Data Source and Delegate to the ViewController. Then simply add the UITableView implementations to your .m file and you're good to go.

    0 讨论(0)
  • 2020-12-06 03:53

    To answer your question, the visual editor simplifies the setup of most controls, view hierarchies, and delegation patterns, but it's still up to the developer to make sure they check out. The implementation of UITableViewController makes certain assumptions and assertions about its view hierarchy that Xcode does not enforce through the visual editor. Given that your desired view hierarchy is unsupported, I have to assume that the editor's behavior is either undefined or irrelevant. For a workaround, see Maxner's suggestion.

    0 讨论(0)
  • 2020-12-06 04:03

    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.

    Once the simulated toolbar is visible, simply drag UIBarButtonItems into it. Use a custom item with a custom view if you need anything more complicated than a button or spacer.

    If you need your toolbar items need to be dynamic, you can maintain a reference via IBOutlets 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.

    See Apple's UINavigationController Class Reference: Displaying a Toolbar.

    0 讨论(0)
提交回复
热议问题