Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gameplayerxp

macrumors newbie
Original poster
Dec 1, 2010
23
0
Sydney
Hi guys,

I'm going to show the contents of files in a UITextView with encoding - so it can show texts in different languages.

But after reading a lot of iOS docs I still don't know which class is used to read file and if UITextView is enough to encode strings.

Can anybody give me some advices? Thanks.
 
In Cocoa, you don't usually need a class to read files. Instead, the class whose data is read from or written to a file has a method for doing that.

Examples:
NSData has dataWithContentsOfFile: and initWithContentsOfFile:.
http://developer.apple.com/library/...Classes/NSData_Class/Reference/Reference.html

NSString has stringWithContentsOfFile:encoding:error: and initWithContentsOfFile:encoding:error:
http://developer.apple.com/library/...lasses/NSString_Class/Reference/NSString.html

There are also many classes that take an NSData rather than a filename, and leave it to you to connect-the-dots between the class, the NSData, and files.

And a UITextView doesn't encode a file into text in a string; that's what NSString does. An NSString contains Unicode characters, which can be in many different languages.
 
Is this a file that you are creating or that the user is providing?

If you are creating the file then make it UTF-8 and load it in that way with the appropriate NSString method.

If the user is providing the file then this is more complicated.

UITextView or UILabel will present unicode text in a single font. If you need multiple fonts or styles you probably need a UIWebView.
 
Is this a file that you are creating or that the user is providing?

If you are creating the file then make it UTF-8 and load it in that way with the appropriate NSString method.

If the user is providing the file then this is more complicated.

UITextView or UILabel will present unicode text in a single font. If you need multiple fonts or styles you probably need a UIWebView.

Good point. The files will be from end users. I'll try UIWebView. Thanks.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.