Devanagari RTF file in UITextView

Visto 254 veces
Saltar al primer mensaje no leído

M. S. Hrishikesh

no leída,
18 may 2012, 13:06:2818/5/12
a 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

no leída,
18 may 2012, 15:41:3018/5/12
a 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

no leída,
19 may 2012, 4:27:4519/5/12
a 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

Responder a todos
Responder al autor
Reenviar
0 mensajes nuevos