Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 08-10-2010, 04:29 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 17
JacobAppleGeek is on a distinguished road
Question Read one line at a time from txt?

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!
JacobAppleGeek is offline   Reply With Quote
Old 08-10-2010, 05:02 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Enschede, Netherlands
Posts: 198
rickrets is on a distinguished road
Default

Code:
NSArray *listItems = [locationString componentsSeparatedByString:@","];
Or change the "," in whatever you put between every line
rickrets is offline   Reply With Quote
Old 08-10-2010, 07:35 PM   #3 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by JacobAppleGeek View Post
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;
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 08-10-2010, 07:36 PM   #4 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 17
JacobAppleGeek is on a distinguished road
Default

Thanks for the quick reply. So I have this code now.

Code:
- (IBAction)loadText:(id)sender {
	
	NSURL *mainURL = [NSURL URLWithString:@"http://192.168.1.102/text.txt"];
	NSString *mainString = [NSString stringWithContentsOfURL:mainURL];
	mainTextView.text = mainString;
	
}
How would I integrate your code into this?

Thanks again.
JacobAppleGeek is offline   Reply With Quote
Old 12-12-2010, 01:06 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Posts: 39
johnhmeyer123 is on a distinguished road
Default

Quote:
Originally Posted by JacobAppleGeek View Post
Thanks for the quick reply. So I have this code now.

Code:
- (IBAction)loadText:(id)sender {
	
	NSURL *mainURL = [NSURL URLWithString:@"http://192.168.1.102/text.txt"];
	NSString *mainString = [NSString stringWithContentsOfURL:mainURL];
	mainTextView.text = mainString;
	
}
How would I integrate your code into this?

Thanks again.
Hey, what is the final code you ended up using for this to work?
johnhmeyer123 is offline   Reply With Quote
Old 12-14-2010, 03:17 PM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 17
JacobAppleGeek is on a distinguished road
Default

Sorry, I never finished this project. :/
JacobAppleGeek is offline   Reply With Quote
Reply

Bookmarks

Tags
line, load, read, server, text

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 356
10 members and 346 guests
bignoggins, Chickenrig, firecall, givensur, iNet, linkmx, michaelhansen, Objective Zero, PlutoPrime, stanny
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,894
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 12:39 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0