scrolling an NSText to the bottom
scrolling an NSText to the bottom
- Subject: scrolling an NSText to the bottom
- From: "Simson Garfinkel" <email@hidden>
- Date: Thu, 15 Nov 2001 09:15:04 -0500
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?