views:

51

answers:

1

I have a subclassed NSTextView that I am manipulating in a separate thread (using performSelectorOnMainThread:withObject:waitUntilDone:) using selectors replaceCharactersInRange:withString:, setSelectedRange:, and insertText:. I'm experiencing flickering of text, and poor performance as the NSTextView updates the display for each and every operation.

Any suggestions on how to control when the display is updated, so I can update it only when actually needed? I tried using various combinations setNeedsDisplay:NO (from both the main and background threads, before and after my updates) which seems to be ignored.

Thanks in advance to anyone who can provide some insight.

+2  A: 

I think you should be manipulating the underlying NSTextStorage for the text view, rather than invoking the view's event-related methods directly. This is a pretty classic example of a Model-View-Controller architecture: the NSTextView is the view and the NSTextStorage is the model. Whenever possible, you want to manipulate the model directly and let the controller/view layers deal with updating the view as they see fit.

Barry Wark
Yep. The Cocoa text system is highly optimized and you will definitely get good performance if you use it the way it's supposed to be used. In this case, modifying the underlying `NSTextStorage` object, which is just a subclass of `NSAttributedString` rather than modifying the view, which is a sledgehammer approach.
Rob Keniger
Thanks! A combination of using the NSTextStorage object in addition to some optimization of the way I was modifying the text did the trick.
stdout