Re: NSTextField refreshes are wacky.
Re: NSTextField refreshes are wacky.
- Subject: Re: NSTextField refreshes are wacky.
- From: Kurt Revis <email@hidden>
- Date: Tue, 12 Mar 2002 14:02:28 -0800
On Tuesday, March 12, 2002, at 04:49 AM, Jonathan Feinberg wrote:
The problem seems to be related to threads. I have since hacked it up
to use NSNotifications from the worker thread to change the status
field in the main thread.
This isn't doing what you think it's doing. NSNotificationCenter will
not cross threads for you. (That is, the method which posts the
notification and the method which receives the notification always run
in the same thread.)
To see this, set breakpoints on -setStatusIndirect: and
-statusNotification: in the code you posted earlier, and run in the
debugger. You'll see that -setStatusIndirect: is called in a secondary
thread (it is not thread #1), which is what you expect. But you will
also break on -statusNotification in the same thread, not in the main
thread (thread #1).
I'm not sure why the text field happens to be working correctly for you
now, but I wouldn't count on that behavior.
Also:
- (void)setStatus:(NSString *)msg
{
[textStatus setStringValue:msg];
[textStatus setNeedsDisplay];
[[textStatus window] displayIfNeeded];
}
Normally you should not need to call -[NSView setNeedsDisplay:] or
-[NSWindow displayIfNeeded] after changing a text field's value (or just
about any value of a control). If you need to do this to get things to
work, it is a pretty good sign that you are, most likely, doing
something wrong.
To sum up: You need to use a different method to run your code in the
main thread. I think some suggestions on how to do this were posted
earlier, but let me know if you can't figure it out.
--
Kurt Revis
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.