Hi i was wondering how should i load rtf or text file into UITextView i use several codes but did't work ,
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"txt"];
myTextView.text = filePath;
thank you .
Hi i was wondering how should i load rtf or text file into UITextView i use several codes but did't work ,
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"txt"];
myTextView.text = filePath;
thank you .
You may try with this:
NSString *myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
myTextView.text = myText;
What you've done so far will get you the name of the file, you need to go one step further and actually read the contents of the file into an NSString, using something like:
NSError *err = nil;
NSString *fileContents = [NSString stringWithContentsOfFile:filePath
encoding:NSUTF8StringEncoding
error:&err];
if (fileContents == nil) {
NSLog("Error reading %@: %@", filePath, err);
} else {
myTextView.text = fileContents;
}
That will work for plain text (assuming your file is in UTF8 encoding); you'll have to do something a lot fancier for RTF (UITextView doesn't know how to display RTF).