Domanda

I'm trying to figure out how to create a new object template at runtime (created by the user) and then use that template to create new objects to populate a list. For example, say you want a list of contacts. The user would create a template that has an NSMutable array of generic objects which contain name, phone, email, etc. Then when they are done creating the template, they can then add a new contact based on that template anytime they want without rebuilding the template. All the template object would consist of is the generic object nested inside of itself with it's value set as different data types, then all those generic objects stored inside of another generic object that contains just an array. I hope I'm not making this sound too confusing... Basically just the ability to create custom object templates at runtime, then be able to use those. Anyone know of a good approach to this? I'd like to make the data storage in my app universal so it can apply to anybody's data. Thanks.

È stato utile?

Soluzione

I'm not exactly sure what your final goal is, but you could take an 'Interface Builder' approach. You have your view to build the template, and then you convert every element to xml form. All you would have to do to load it is read the xml, create the appropriate UI elements, and add them at the right location in a container view. One problem with this approach is if you need to send data to an element, it would be almost impossible to get the right element if there are multiple of that type in your template. You could use an array, dictionary, or even the xml to store a key (the name of the element), and a value (the element, this would not be required using the xml approach). Sorry if this is confusing.

Altri suggerimenti

There are several viable options for reading and writing objects to the disk on iOS. The most famous and widely used being Core Data and Plists.

If you are a beginner, I would recommend saving an array of attributes (possibly as strings?) for a custom object 'template'. See here for a tutorial, and search SO for anything else that might come up.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top