Quote:
Originally Posted by JacobAppleGeek
Hi!
First post! I have a UITextView that needs to show one line at a time of a txt file loaded from a server. I know how to load the file on the server to the UITextView's text but I don't know how to get it to display one line at a time.
Any ideas?
Thanks!
|
The other poster had the right idea.
Load all the contents of your sever file into an NSString. Let's call it fileText.
Then use a line like:
Code:
NSArray* lines = [fileText componentsSeparatedByString: @"\n"];
That will give you an array, lines, where each element contains a separate line of text ("\n" is the escaped form of a newline).
Then you can loop through the resulting array, adding one line at a time to your text view, using code something like this (assuming "index" is the line number of the text you want to put into your text view) :
Code:
NSString* textLine = [lines objectAtIndex: index];
myTextView.text = textLine;