• 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
NSThread and UI
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSThread and UI


  • Subject: NSThread and UI
  • From: Torsten Curdt <email@hidden>
  • Date: Sun, 20 Jul 2008 23:01:59 +0200

AFAIU accessing UI elements from within an NSThread is a big no-no.

So in the following naive code I would have to either wrap the calls to the progressIndicator object through a performSelectorOnMainThread or could send NSNotifications to update it on the main thread. But looking around the net I haven't seen any example where either of both approaches is being used. Did I just not look at the right places?

I am also wondering whether using NSRunCriticalAlertPanel() in the thread is OK or not.

cheers
--
Torsten


[NSThread detachNewThreadSelector:@selector(convert) toTarget:self withObject:nil];

- (void) convert {

    [progressIndicator setMaxValue:10];
    [progressIndicator startAnimation:self];

	if (...) {
		NSRunCriticalAlertPanel(...);
	}

    int i;
    for(i = 0; i < 10; i++) {
        [progressIndicator setDoubleValue:(double)i];
        [progressIndicator displayIfNeeded];
        ...
    }

    [progressIndicator stopAnimation:self];
}

_______________________________________________

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: NSThread and UI
      • From: Chris Hanson <email@hidden>
    • Re: NSThread and UI
      • From: Ken Thomases <email@hidden>
    • Re: NSThread and UI
      • From: "Bruce Johnson" <email@hidden>
  • Prev by Date: Re: StopWatch Application Help
  • Next by Date: Re: drawRect doesn't get called when using CoreAnimation?
  • Previous by thread: Core Data Sync Question (Managed Object Contexts)
  • Next by thread: Re: NSThread and UI
  • Index(es):
    • Date
    • Thread