Re: scrolling an NSText to the bottom
Re: scrolling an NSText to the bottom
- Subject: Re: scrolling an NSText to the bottom
- From: Eric Peyton <email@hidden>
- Date: Thu, 15 Nov 2001 08:49:13 -0600
Try this ...
[theText scrollRangeToVisible:NSMakeRange([[theText textStorage]
length], 0)];
I use it in all of my console like settings to scroll to the bottom on
input ...
My entire method ...
- (void)addMessageToConsole:(NSString *)aMessage andDisplay:(BOOL)display
{
if ([[theText textStorage] length]) {
[theText replaceCharactersInRange:NSMakeRange([[theText
textStorage] length], 0) withString:@" \n"];
}
[theText replaceCharactersInRange:NSMakeRange([[theText textStorage]
length], 0) withString:[[NSDate date]
descriptionWithCalendarFormat:@"%I:%M %p" timeZone:nil locale:nil]];
[theText replaceCharactersInRange:NSMakeRange([[theText textStorage]
length], 0) withString:@" - "];
[theText replaceCharactersInRange:NSMakeRange([[theText textStorage]
length], 0) withString:aMessage];
[theText scrollRangeToVisible:NSMakeRange([[theText textStorage]
length], 0)];
if (display) {
[self display];
}
return;
}
On Thursday, November 15, 2001, at 08:15 AM, Simson Garfinkel wrote:
NeXTSTEP Text objects supported scrollToSel, but that functionality
appears
to be gone from the new NSText and NSTextView classes.
I am attempting to scroll an NSTextView object to the bottom. Here is my
sample code. It doesn't work:
- (IBAction)addLines:(id)sender
{
int i;
float height;
for(i=0;i<100;i++){
NSString *str = [NSString stringWithFormat:@"Here is another
line,
#%d\n",i];
int len = [[theText string] length];
[theText
replaceCharactersInRange:NSMakeRange(len,0)
withString:str];
}
if([theText isFlipped]){
NSLog(@"theText is flipped");
}
/* Now scroll to see the last line */
height = [theText frame].size.height;
NSLog(@"Attempting to scroll to 0,%f in frame",height);
if([theText scrollRectToVisible:NSMakeRect(0,height-1,1,1)]){
NSLog(@"Scrolling was performed");
}
}
@end
You'll note that this code verifies that theText is flipped (so the
lower-left is 0,height-1, and not 0,0). But no scrolling happens.
Anybody
have a clue?
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev