• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: scrolling an NSText to the bottom
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: scrolling an NSText to the bottom


  • Subject: Re: scrolling an NSText to the bottom
  • From: Ben Hines <email@hidden>
  • Date: Fri, 16 Nov 2001 21:46:55 -0800

use scrollRangeToVisible instead of scrollRectToVisible, it will be much simpler.

This is from sample code on cocoadevcentral, the Wrapping UNIX Commands II tutorial:

NSRange theEnd=NSMakeRange([[textView string] length],0);

// append new string to the end
[textView replaceCharactersInRange:theEnd withString:myString];
theEnd.location+=[myString length]; // the end has moved
[textView scrollRangeToVisible:theEnd];


-Ben


At 9:15 AM -0500 11/15/01, 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


--


References: 
 >scrolling an NSText to the bottom (From: "Simson Garfinkel" <email@hidden>)

  • Prev by Date: NSUserDefaults key validation
  • Next by Date: Re: Oddity
  • Previous by thread: Re: scrolling an NSText to the bottom
  • Next by thread: sub-projects in ProjectBuilder
  • Index(es):
    • Date
    • Thread