Re: Simple Network Client Design (newbie alert)
Re: Simple Network Client Design (newbie alert)
- Subject: Re: Simple Network Client Design (newbie alert)
- From: Malte Tancred <email@hidden>
- Date: Wed, 30 Jan 2002 17:33:53 +0100
You can add text to the text storage of the text view.
A category could be added to NSTextView that handles appending
a string as well as scrolling if that is desired and necessary:
@implementation NSTextView (AppendingAndScrolling)
- (void)appendString:(NSString *)string scrollIfNecessary:(BOOL)flag {
NSScrollView *enclosingScrollView = nil;
NSScroller *scroller = nil;
BOOL shouldScroll = NO;
NSAttributedString *aString = nil;
NSRange range;
if (flag) {
enclosingScrollView = [self enclosingScrollView];
scroller = [enclosingScrollView verticalScroller];
shouldScroll = ([scroller floatValue] == 1.0) ? YES : NO;
}
aString = [[NSAttributedString alloc] initWithString:string];
[[self textStorage] appendAttributedString:aString];
[aString release];
if (shouldScroll) {
range = NSMakeRange([[self textStorage] length], 0);
[self scrollRangeToVisible:range];
}
}
@end
On wednesday, january 30, 2002, at 04:42 , Ross Hayden wrote:
When I was learning network programming on Unix, I wrote a simple TCP
client and server pair, where the server would echo back the lines of
text sent to it by the client. I typed in a line of text at my client,
which then sent it to the server which would send it back to the client
and display on my terminal.
I'm trying now to rewrite the client in Cocoa.
I've redesigned it so that reading from the socket blocks in a thread
and doesn't hold up my user interface. I hope that's the best way to
do that?
I created an NSTextView in which to display text echoed back from the
server. My problem here is understanding how I can inject data into an
NSTextView from my socket reader thread. I tried using setString: but
what happens is that only the top three lines of my NSTextView ever
fill with text before scrolling starts, even though the NSTextView box
itself is large enough to display about 15 lines.
I also tried insertText: which never displays a thing.
I'm clearly lost here! Any help is much appreciated.
Ross
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.