Search code examples
iosxlform

Use XLForm with a toolbar


I want to launch a XLForms view controller as a Form Sheet. I want the controller to have a toolbar at the top and then the XLForm tableview underneath it. How?

The view controller isn't a navigation controller and so I need to add a toolbar at the top (or bottom) where I can add buttons. So how do I do this?


Solution

  • It turns out that this is not too difficult. I just wish that it was documented somewhere.

    All the sample code I could find showed the top view controller inheriting from XLFormViewController. In this case, the IB controller only requires a topline view.

    I wanted to expand the view controller to have other components in it other than just a "View" object. I wanted a toolbar across the top and a couple of other things.

    So, here's how I did it. I'm not sure that this is the best approach but it did work.

    1. Create the View Controller in IB and add all the components you want.
    2. Include a TableView object someone in your design
    3. Go into the "Assistant Editor" and hook the TableView object to the "tableView" object defined in XLFormViewController.h by ctrl-dragging and dropping on the IBOutlet tableView object.
    4. All other controls work as usual.

    Important: Do not treat the tableView object like a regular object. In other words, do not implement UITableViewDataSource and UITableViewDelegate methods.

    Hope this helps.