iPhone Programming: Reading Plain Text Files into your app.

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
809 views
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Sep 24, 2011

A tutorial teaching you how to read text form an external plain text file and put it into a UITextView

IMPORTANT: IT MUST BE A PLAIN .TXT FILE. If your textEdit will not allow you to save as .txt and says it must be a .rtf or .txt.rtf go to this link to change your textEdit preferences. Its an apple support page.

http://support.apple.com/kb/ta20406

When you save your textFile choose "Unicode (UTF-8)" or "(UTF-16) as Plain Text Encoding. You will have to modify all existing .rtf files you wish to use.

Main code used:

//If you chose UTF-16 change to NSUTF16StringEncoding
text.text = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"YourFileName" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil];

Twitter: http://twitter.com/failcakeapps
Apple Developer Center: http://developer.apple.com/devcenter/ios/index.action
Website: http://failcake.webs.com/
Channel: http://youtube.com/milmersxcode

  • likes, 0 dislikes

Link to this comment:

Share to:

Uploader Comments (MilmersXcode)

  • instead of this type of txt, my txt file is a URL. How can I view this txt URL on my iPhone screen? How can I change the attributes of this view? A part of this URL txt is to be entered by the user. How can I do it? I am new on iPhone development and your tutorials are great and easy to understand and implement. Thank you very much for all of your tutorials.

  • @flytoismail Ok so you have a txt file that contains a URL. Correct? Then you want to display this txt file, let the user edit it and then save it? Or show the completed URL in a webView?

    Milmer.

  • Once loaded with iOS Simulator it doesn't show me the content I added to the plain text. Do you know where the problem could be? Thanks in advance.

  • @nxchannel Maybe your file path is wrong. Make sure you typed the exact name of the file. Sometimes, like with PDFs, the file doesn't display until you load it on your device. Have you tried that?

    If this doesn't work, PM with your main code and I will try and debug it. Be sure to include the file name of the file you are trying to show :D

    Milmer

  • @MilmersXcode Thanks a lot for your answer. I actually did everything exactly as you did. There are also no issues, so everything seems to be fine except the text inside. How do you prefer to get the main code from me? You certainly can find out where the problem is. I appreciate that :)

  • @nxchannel Just PM me and I will send you my email. You can then send me the file that way.

see all

All Comments (9)

Sign In or Sign Up now to post a comment!
  • I am looking for someone in or around london that can help me with my Mac app, it is a simple interface for sending messages to a local server that controls my laser scanners, I have built the gui and have the same project already written in VB6. anyone?????

  • No, I have a URL which is a plain text file. I want to display this URL. Since it is a plain text file, can it be shown on a textView or should it be shown on webView? The user will see it on his screen. The user will not edit it or save it. flytoismail@yahoo.com Thank you for your reply and help.

  • just reading?

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more