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

Textview is overwriting itself


  • Subject: Textview is overwriting itself
  • From: Christopher Woodruff <email@hidden>
  • Date: Fri, 21 Mar 2008 11:37:35 -0700

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.

Regards,

Chris Woodruff

_______________________________________________

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


  • Follow-Ups:
    • Re: Textview is overwriting itself
      • From: Ross Carter <email@hidden>
  • Prev by Date: Re: Intercepting retain/release of object
  • Next by Date: Re: disabling NSButton?
  • Previous by thread: Re: iPhone/iPod Touch
  • Next by thread: Re: Textview is overwriting itself
  • Index(es):
    • Date
    • Thread