Devanagari RTF file in UITextView

254 views
Skip to first unread message

M. S. Hrishikesh

unread,
May 18, 2012, 1:06:28 PM5/18/12
to cocoa-...@googlegroups.com
I am trying to read a Devanagari RTF file into a UI text view. My code is like below

  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"File1" ofType:@"rtf"];

  NSData *myData = [NSData dataWithContentsOfFile:filePath];

  if(myData) {

            _textContent = [[NSString alloc] initWithData:myData encoding:NSUnicodeStringEncoding];

     }


Where _textContent is a NSString*.

This does not work. When I print _testContent it prints characters in a different language.

When I preload the UITextView in storyboard by copy posting the test and print textView.text then the correct Devanagari text is printed.

How do I load my rtf file into a UITextView? 

Thanks
Hrishi


Benjamin Stahlhood II

unread,
May 18, 2012, 3:41:30 PM5/18/12
to cocoa-...@googlegroups.com
Try something like the following...

On May 18, 2012, at 1:06 PM, M. S. Hrishikesh wrote:

I am trying to read a Devanagari RTF file into a UI text view. My code is like below

  NSString *filePath = [[NSBundle mainBundle] pathForResource:@"File1" ofType:@"rtf"];

NSError *stringError = nil;
NSString *fileContentString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8Encoding error:&stringError];
if (!stringError) {
self.myTextView.text = fileContentString;
}

  NSData *myData = [NSData dataWithContentsOfFile:filePath];
  if(myData) {
            _textContent = [[NSString alloc] initWithData:myData encoding:NSUnicodeStringEncoding];
     }

Where _textContent is a NSString*.

This does not work. When I print _testContent it prints characters in a different language.

When I preload the UITextView in storyboard by copy posting the test and print textView.text then the correct Devanagari text is printed.

How do I load my rtf file into a UITextView? 

Thanks
Hrishi



--
Ben S. Stahlhood II
DS MediaLabs

drops

unread,
May 19, 2012, 4:27:45 AM5/19/12
to cocoa-...@googlegroups.com
This cannot work because iOS does not support rich text loading from RTF files or any other rich text. If you have special unicode sequences in a PLAIN TEXT file then you can load it via this method.

Regards
Oliver Drobnik

Cocoanetics.com

Reply all
Reply to author
Forward
0 new messages