views:

25

answers:

1

Dear Developers,

I am trying to integrate a question/answer section to one of my apps.

I wanted to use a Utility style application where the question is loaded as a Uilable in the first view, and the answer is loaded in the flippedview.

I was hoping to load the question and answer data from a plist, and integrate a shuffle option so that the questions can be mixed up.

Is the plist method suitable here? does anybody have experience of making this sort of app? are there any examples on the web/in books where i could see some source code?

Your help is most apprecaited.

j


Update:

OK - i have tried to make this work.

Here is my plist (DataDetail1.plist):

Root...............................(Array)
........Item 0.....................(Dictionary)
.................Question..........(string)  ///Question text////
.................Answer............(string) ///Answer text/////
........Item 2.....................(Dictionary)
.................Question..........(strings) //Question text////
.................Answer............(strings) //Answer text/////

I was thinking that i could declare the plist as an NSarray:

- (void)viewDidLoad {
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"DataDetail1" ofType:@"plist"]; //Defines path for DATA For ARRAY//
NSArray* tmpArray = [[NSArray alloc] 
                            initWithContentsOfFile:path]; //initialises the contents of the ARRAY with the PLIST"
self.DataList1 = tmpArray; 
[tmpArray release];

Then assign a Key to the UILable in the first view;

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
Label1.text = [DataList1 objectForKey:Question_KEY];

It is at this point that i hit trouble - i can't use the 'objectForKey' method with an NSArray.

How do i get this to work?

j

p.s.

once this is working, what code would i need to make the flippedView load the 'Answer' key from a given Item within the Plist?

A: 

You can use a plist to store just about anything but the problem they have is that they don't scale. You have to load the entire plist in at once and instantiate all the objects the plist serializes. That is okay for a few small objects but it very quickly eats your memory and becomes difficult to manage as the number, size and complexity of the objects grow.

If each file represents just a few dozen cards each with just a text questions and a text answer, then plist would probably work fine. When you get a larger number of cards and/or start adding in graphics then it would break down.

Edit:

This:

Label1.text = [DataList1 objectForKey:Question_KEY];

... will not work. objectForKey: is a method of NSDictionary not NSArray. You have to get the dictionary at a specific index of the array and send that the objectForKey:message.. You need something like:

Label1.text = [[DataList1 objectAtIndex:1] objectForKey:Question_KEY];
TechZen
ok - that is good to know! Perhaps i should use multiple small plists with switches so that they aren't all loaded at once.
james coleman
That would work.
TechZen
Thanks TechZen - i really appreciate your help.
james coleman