• 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: NSTextField overwrites itself
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField overwrites itself


  • Subject: Re: NSTextField overwrites itself
  • From: email@hidden
  • Date: Tue, 21 May 2002 13:37:29 -0700

Mark Slater wrote:
|I'm trying to implement a window that monitors a thread. Sometimes it
|all looks good, but more often than not, the NSTextFields on the window
|will overwrite themselves... you can make out the current value and one
|or more previous values. The thread processes data in batches, and at
|the end of each batch, it sends an update notification to the window
|controller class. There is generally 1-5 seconds between updates...
|sometimes longer but rarely shorter... and they don't ever seem to
|overlap. Is there some kind of trick in changing the text field string
|that ensures only the current value is drawn and the old value is erased
|first?

Assuming all is otherwise well, that's what setStringValue: does. However, I rather suspect that all is *not* otherwise well. The key question: what thread are you updating the text field from: the main UI thread, or one of your other threads (one started using detachNewThreadSelector:toTarget:withObject:)? If it's from one of your own threads, that's likely the problem. The AppKit classes are *not* thread-safe; their methods cannot be safely called from any thread other than the UI thread. The problem is that the UI thread is busily tending the UI. If your thread *also* tries to change UI data, both threads will be trying to change the same data at the same time. What actually happens depends on what order everything ends up happening in.
This problem (trying to change the UI from a non-UI thread) has been discussed in previous postings, so search the archives for more information.

Glen Fisher
_______________________________________________
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.

References: 
 >NSTextField overwrites itself (From: Mark Slater <email@hidden>)

  • Prev by Date: Re: Getting 'mouseMoved' events
  • Next by Date: Re: Newbie question: setting a NSNumber
  • Previous by thread: Re: NSTextField overwrites itself
  • Next by thread: Re: NSTextField overwrites itself
  • Index(es):
    • Date
    • Thread