Take the 2-minute tour ×

I have a custom plist and wish to display it in a UITextView in an IPad.

In the plist, I want to retrieve both "QuestionTitle" and "QuestionAnswer" from each item.

The page is basically a Answer Sheet Page, a page with a UITextView which displays all questions and answers once page is loaded.

    - (void)viewDidLoad
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"DLquestions.plist"];
    NSDictionary *DLDict = [[NSDictionary alloc] initWithContentsOfFile:filePath];

Is there a way for one to populate plist details into a UITextView in a specific order line by line?

Like for example,

QuestionTitle (e.g. what is 1 + 1?)

QuestionAnswer (e.g. 2)

QuestionTitle (e.g. What is 2 + 2?)

QuestionAnswer (e.g. 4)

I have been stuck for a while now.. Please help me, Thanks in advance.

share|improve this question
add comment

2 Answers

up vote 0 down vote accepted

Create a string from your plist and display it in UITextView, as follows:

    for(int i=0;i<[plistArray count];i++)
       someString = [someString stringByAppendingFormat:@"%@ \n %@",[[plistArray objectAtIndex:i] objectForKey:@"QuestionTitle"],[[plistArray objectAtIndex:i] objectForKey:@"QuestionAnswer"]];


    //Display someString in UITextView.
yourTextView.text = someString;

Your plist contains array of Dictionarys, otherwise get all keys and values and create NSString as above and display in UITextView.

share|improve this answer
Thanks! Can understand the code there, I tried implementing it. However they are giving me "use of unidentifier 'plistArray' and 'someString'". I'm new to iOS programming, how do I fix this error? Many thanks for the help! –  user1583491 Aug 22 '12 at 5:22
add comment

If your dictionary format is something like this,

key Value(NSArray)

1 {QuestionTitle (e.g. what is 1 + 1?),QuestionAnswer (e.g. 2)}

2 {QuestionTitle (e.g. what is 2 + 2?),QuestionAnswer (e.g. 4)}


NSDictionary *dict;
NSArray *keys = [dict allKeys];
for (int i=0; i< [keys count]; i++) {
    NSArray *object = [dict objectForKey:[keys objectAtIndex:i]];
    NSString *question = [object objectAtIndex:0];
    NSString *answer = [object objectAtIndex:1];
    textView.text = [textView.text stringByAppendingString:@"\n"];
    textView.text = [textView.text stringByAppendingString:question];
    textView.text = [textView.text stringByAppendingString:answer];
share|improve this answer
Hi tried ur solution but i gotten this error 2012-08-22 13:35:46.926 Learning Journey[14672:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary length]: unrecognized selector sent to instance 0x8ea96a0' –  user1583491 Aug 22 '12 at 5:37
add comment

Your Answer


