• 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: Textview is overwriting itself
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Textview is overwriting itself


  • Subject: Re: Textview is overwriting itself
  • From: Ross Carter <email@hidden>
  • Date: Mon, 24 Mar 2008 12:21:57 -0400


On Mar 21, 2008, at 2:37 PM, Christopher Woodruff wrote:
I used a textview to work as an automatically scrolling log window for a real time data output feed. I limit the size of the textstorage programmatically. When I fill the textstorage to my programmatic size limit (currently is 16384 characters), the textview overwrites itself momentarily. By overwrite, I mean that the new text displays on top of the existing text, such that you can't read it anymore. The rate I update the textview is about 1-3 times a second.

I have posted a few screenshots of this behavior here: http://picasaweb.google.com/cswoodruff/CocoaTroubleshooting/photo#5180264259131797666 .

Here are the relevent code chunks:

- (void)handleNewData:(id)newData
{
scrollPos [[receiverScroll verticalScroller] floatValue]; //Get the current scrollbar position

if(newData ! nil)
{
NSRange endRange;
endRange.location [[receiverConsole textStorage] length];
endRange.length 0;
[receiverConsole replaceCharactersInRange:endRange withString:newData]; //Append the new text to the textStorage mutableString
}

if([[receiverConsole textStorage] length] > TEXT_SIZE)
{
[self deleteToSize];
}
}


- (void)deleteToSize
{
int charToDelete [[receiverConsole textStorage] length] - TEXT_SIZE;
[[receiverConsole textStorage] deleteCharactersInRange:NSMakeRange(0, charToDelete)];
}


- (void)scrollToBottom
{
//if the scrollbar *was all the way at the bottom before the new text was appended, then scroll down to the bottom
if( scrollPos == 1.0 )
{
NSRange endRange;
endRange.location [[receiverConsole textStorage] length];
endRange.length 0;
[receiverConsole scrollRangeToVisible:endRange];
}
}



In the Init method:
[receiverScroll setPostsFrameChangedNotifications:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollToBottom) name:NSViewFrameDidChangeNotification object:nil];


I am running this code on OSX 10.4.11 on a MacBook Pro 2.4 GHz. If anyone has any idea of what I'm doing wrong here, please let me know. I still consider myself a beginner at Objective-C / Cocoa, so I welcome ideas on how to make this better.


Chris, since no one else has chimed in, I'll make a suggestion. Rather than use NSViewFrameDidChangeNotification and scrollRangeToVisible, try NSViewBoundsDidChangeNotification and scrollToPoint:. The technique is described in the Scroll View Programming Guide under "Synchronizing Scroll Views," http://developer.apple.com/documentation/Cocoa/Conceptual/NSScrollViewGuide/Articles/SynchroScroll.html#/ /apple_ref/doc/uid/TP40003537


If that doesn't work then I'd give the layout manager a chance to finish layout before adjusting the scroll view. The NSLayoutManager delegate method didCompleteLayoutForTextContainer:atEnd: will tell you when layout is complete.

Ross
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Textview is overwriting itself (From: Christopher Woodruff <email@hidden>)

  • Prev by Date: Core Data & Passwords
  • Next by Date: Re: Garbage collection - was Beginner with Cocoa
  • Previous by thread: Textview is overwriting itself
  • Next by thread: Beginner with Cocoa
  • Index(es):
    • Date
    • Thread