Re: NSView redisplay - what am I missing?
Re: NSView redisplay - what am I missing?
- Subject: Re: NSView redisplay - what am I missing?
- From: Dragan Milić <email@hidden>
- Date: Wed, 25 May 2005 09:53:03 +0200
Well, I'm just doing what I've been doing before, and I'm not calling -setNeedsDisplay: from my thread. The separate thread deals with data processing. When certain amount of processing is done, an notification (let's call it note1) is posted and, window controller is responsible to catch it and update user interface (progress bar) in the main thread. Also, when some bigger chunk of data is done, some new items in data model are created, so another notification (note2) is posted by separate thread. Upon catching that notification, window controller asks my custom view to reload its data (which does so by talking to data source object, which in this case is the same window controller) and after getting those new items, it redisplays itself. So, all redisplaying is done in the main thread (and I understand that I only mark it as needing redisplay, it won't happen immediately). The strange thing is that main thread enters -drawRect: method of my custom view even when it's not asked to reload its data. It's just like window controller asks custom view to reload not only upon recieving note2, but also upon recieving note1 as well, but it's not window controller's request, I've checked the code very carefully! Now, the question remains, why is this not happening when instantiating custom view in IB, but only if I create it programatically? I know this sounds silly and probably it's hard to answer, but it's just what I'm experiencing.
Milke
On 25.
мај 2005., at 9:14, Bob Ippolito wrote:
On May 24, 2005, at 11:55 PM, Dragan Milić wrote:
can someone please explain me this strange behavior: I've created my custom NSView (actually NSControl) class, which shows some items and other stuff. When an application crunches some data (in separate thread), that views is constantly being updated, by talking to its dataSource object, which in turns supply newly created items and at the end, the whole view is redisplayed, by sending -setNeedsDisplay: message to itself. And that's OK. In the same window, there is NSProgressIndicator instance, which shows how data crunching is progressing and its value is updated much more frequently than the custom view is redisplayed. But somehow, "someone" is sending - setNeedsDisplay: to my view, even if there's no new item to show. Just as NSProgressIndicator is being updated, my view enters its -drawRect: method. I confirmed that by putting log message inside that method. Now, that's happening when creating custom view programatically. If I instantiate it in IB (I defined -initWithCoder: method, which looks exactly the same as -initWithFrame: for programatic creation, except for different message sent to super, of course), my custom view behaves just right, no superfluous redisplaying. The sole reason I create it programatically is to put it inside NSScrollView instantiated in IB, since I've been to lazy to create separate IB palette which includes NSScrollView as well. I can easily solve this problem by instantiating the view in IB, but I'm really curious whether I'm missing something. I 'd like to know what might be the reason for superfluous redisplaying when creating view programatically.
Sounds like you're not following the threading rules. You can't call setNeedsDisplay: from your thread, it needs to be done on the main thread. Threading and drawing has come up like three times this week, I suggest searching the archives.
http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/index.html
-bob
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden