I’m creating an iPhone app and I need the ability to dynamically create a “form” where a user can input data. For example, suppose I was making the Dominoes Pizza app where you can order pizza through a in-app “form”. This form has different section headings (Pizza, Pasta, Salad…etc) different “radio button” like options (Meat pizza, cheese pizza…etc) and some condition options (for example, you might only see options for pizza toppings if you have selected the pizza checkbox). My app will be similar to that, with a form with many checkboxes, radio buttons, drop downs…etc.
My question is what would be the best way to store the information used to dynamically create such a form? My requirements are that it be easy to change (say cheese pizzas now cost $2 more) and it should be able to be changed by a person with limited programming experience.
My first instinct would be to use XML such as this:
<Item>Pizza</Item>
<Type>Dropdown List</Type>
<Cost> $5.0 </Cost>
<Option> Cheese Pizza </Option>
<Option> Pepperoni Pizza </Option>
<Option> Meat Pizza </Option>
<Item>Salad</Item>
<Type>Radio Buttons</Type>
<Cost> $2.0 </Cost>
<Option> Yummy Salad </Option>
<Option> Icky Salad </Option>
Having this file in my app, I could then just parse this and whenever I see a “Radio button” type, create a radio button and whenever I see a “Drop down list” create a drop down list. The only issue with this is it may make it difficult to make conditional options such as only show salad item if the use has already selected a pizza.
Is this the most appropriate technology to use for this case? XML? Note that I don’t want it to strictly be a web app because I want to be able to use Objective-C objects such as “UISegmentedControl”.
Yes, XML is definitely a good choice. You should also consider using JSON. Generate the information on your web service, encode it using JSON, download the JSON string within the app, then parse and save the string.
Once you have the data in the app, I would use a
UITableViewto dynamically create the form. The datasource of aUITableViewis aNSArray, which is really easy to get from a XML or JSON parse.