 |
 |
Displaying a txt file from the internet in a NSTextView?
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Is this possible? If so is there any sample code or tutorial?
Im looking to gather the text from a .txt file, and for it to display in a text view. If possible, id rather use a rtf file.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status:
Offline
|
|
Originally posted by iOliverC:
Is this possible? If so is there any sample code or tutorial?
Im looking to gather the text from a .txt file, and for it to display in a text view. If possible, id rather use a rtf file.
NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.foo.bar/file.txt"]];
[myTextView setString:string];
Isn't Cocoa great?
Using rtf instead of raw text isn't much harder, check the docs for NSTextView and NSText.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
I get the code, but im just not sure how to make the text view to display it. Sorry for my newbness. Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
//Line 1:
NSString *string = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.foo.bar/file.txt"]];
//Line 2:
[myTextView setString:string];
Line 1 creates an NSString and initiates it with the indicated URL data. So you end up with an NSString holding your data.
Line 2 says that myTextview is to be sent a message to set its display with the string from Line 1. Substitute myTextView with whatever name you've given your NSTextView widget in Interface Builder and you your are set.
Cocoa is freaking awesome!

|
|
|
| |
|
|
|
 |
|
 |
|
Banned
Join Date: Apr 2002
Location: -
Status:
Offline
|
|
Originally posted by iOliverC:
I get the code, but im just not sure how to make the text view to display it. Sorry for my newbness. Thanks!
you just send the view a - setString  NSString *)string message
e.g.
[myView setString;@"hello"]
The documentation says it all.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Jun 2002
Status:
Offline
|
|
Hey guys, I got the code and thought back to something similar and put it in awakeFromNib. Now onto the rtf challenge =-)
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |