I have created a plist file that looks like this:
From this is am able to extract all plist info into an NSArray:
-(NSArray *)Topics
{
if(!_Topics)
{
_Topics = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"TopicData" ofType:@"plist"]];
}
return _Topics;
}
And use this array to load a tableview of TopicTitle's:
cell.textLabel.text = [[self.Topics objectAtIndex:indexPath.row] valueForKey:@"TopicTitle"];
When a row in the table is selected, I am passing the dictionary named 'Questions' to the next ViewController like this:
NSDictionary *questions = [[self.Topics objectAtIndex:indexPath.row] valueForKey:@"Questions"];
[self.detailViewController setQuestions:(questions)];
From here I want to loop through each 'Question' dictionary and load the 'QuestionText' and 'AnswerOne / Two...' strings into an array of objects by doing something like this:
TopicQuestions = [NSMutableArray array];
for(NSDictionary *ques in self.Questions)
{
Question* q = [[Question alloc] init];
q.Question = (NSString*)[ques objectForKey:@"QuestionText"];
q.AnswerOne = (NSString*)[ques objectForKey:@"QuestionText"];
q.AnswerTwo = (NSString*)[ques objectForKey:@"QuestionText"];
q.AnswerThree = (NSString*)[ques objectForKey:@"QuestionText"];
q.AnswerFour = (NSString*)[ques objectForKey:@"QuestionText"];
[TopicQuestions addObject:q];
}
But the 'Questions' dictionary does not seem to have this data available, it knows there are 4 child objects, but does not have all the key - pair values of these objects:
So my question is how should I pass the 'Questions' dictionary to the next ViewController so that I will still be able to access the 'QuestionText' and 'AnswerOne / Two...' nodes?
Or is there a better way of reading the strings without looping through each 'Question' dictionary?