Search This Blog

Friday, 10 May 2013

Text file-iOS

Hello friends,

Here i am with something different not to read a text from text file or rtf file and display the text in UITextView , UILabel or UITextField....Whichever you like...

For this simple example , i want you to first drag and drop a txt or rtf file into your project in xcode.

Then simply do the following:

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"txt"];
//type may change as per the format of your file in our case it can be txt or rtf
 depending on the extension of your file.
Next do the following:
NSString *myText = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil]; 

You can pass this 'myText' to your UI Element 'text' property.

That's it you are done :)