having a bit of panic and really really need some help with this!
I’m making an app to fill in forms. The layout of the forms are created on a web server, and then the ipad app syncs with it, copies the form database, and then runs it locally.
One type of text field is a UITextView where the user can input text either by writing directly to the field, or by using one of many pre-defined texts (also defined on the web server).
To use a pre-defined text, the user touches/selects the tablecell that is containing the UITextView, and then a category-picker-view is pushed on the screen. On selection of category, the user gets a list of texts, and upon selection of text, the user gets a simple uitextview to edit it before insert. With a save button, the user then gets moved back to the original view where the chosen text is now added.
Flowchart:
root view with input fields-> category picker -> text picker -> editor
/\ |
'------------------------------save text------------------------'
The problem is that when any other view loads, all other input fields are emptied! The value of the selected field is passed via prepareForSegue, so that one is kept.
I have a save function which saves all fields to the database. I tried to put a call for it inside the prepareforsegue call, but it either crashes or does nothing.
Question: Where could i put the save function? Could/should I do it another way? Thought about putting all tag’s values in a dictionary inside my appDelegate instead of running the save-function, but how could i update it every time an input field is edited?
Also – would putting the categorypicker etc in some kind of popover/modal/popup-view instead of the push segue prevent the values from clearing? I’ve got no experience from such views, could someone give a good starting point? (perhaps a good tutorial rather than heavy apple docs 🙂
I have a deadline for this tomorrow, with LOADS of more things to complete as well, so I’m very very grateful for ANY help!!
Thank you for your time!!
/Dave
I think your problem is caused by an absence of a model (in terms of the model-view-controller pattern). A model that represents your form data (e.g., custom object, NSArray, NSDictionary) should be updating the view and should be passed in prepareForSegue, not an input field’s value.
Specifically, create a new property that maintains the latest data. When the user makes an edit or selects a category for some field, update the model. Then, when you return to your form view controller, use viewDidAppear to update the input fields to their latest values.