Priya
Priya

Reputation: 157

How to retrieve text message in UITextView using plist?

I save the text message into plist but I don't know how to retrieve it from plist. How can one retrieve a text message in UITextView using plist?

Upvotes: 0

Views: 1054

Answers (3)

Hariprasad
Hariprasad

Reputation: 1084

You might have saved your data in to the p-list file in the form of NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary,all of these classes defines a method to init them selfs with contents of a file as :initWithContentsOfFile:.You should specify the path where you saved the p-list file as parameter to this method.You can save and retrieve string objects directly in the same manner.after initializing the string object(say stringFromPlist) with file contents write the following code to display the text:

yourTextView.text=stringFromPlist;

You may also want to see p-list programming guide

Upvotes: 1

Sudhanshu
Sudhanshu

Reputation: 3960

@Try doing this and you will get the data in you UItextView and you have give the text data type as NSString in your plist.

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"plistname" ofType:@"plist"];  
    BOOL success = [fileManager fileExistsAtPath:filePath];
    if(!success){
        NSLog(@"not success");
    }


    NSString *data = [[NSString alloc] initWithContentsOfFile:filePath];
    [self.TextView setText:data];
    [self.TextView setFont:[UIFont fontWithName:@"Helvetica" size:16.0]];
    [data release];

Hope it will help you! Good Luck!

Upvotes: 1

V.V
V.V

Reputation: 3094

Here the link that will show you how to retrive data from a .plist file to array.

And there on you can perform the action as you are needed.

Upvotes: 0

Related Questions