• 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: updating NSTextField before spinner animates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: updating NSTextField before spinner animates


  • Subject: Re: updating NSTextField before spinner animates
  • From: Fritz Anderson <email@hidden>
  • Date: Tue, 11 Nov 2014 10:01:02 -0600

On 11 Nov 2014, at 4:15 AM, sqwarqDev <email@hidden> wrote:

> I have  an NSTextView, whose string I want to update while I wait for another method to complete. Since this method is going to take around 10-30 seconds, I'm displaying a spinner progress indicator.
>
> However, I want the text field to update before (and, ideall, during, but I'll settle for before) the spinner starts, but no matter where I put the text field message, it waits until the spinner has finished before updating. I've even tested to make sure the update happens first (see the conditional clause below), but the update is not shown in the view until the spinner finishes.
>
...
> [_mySpinner startAnimation:nil];
>
> [_infoField setString:@"display something..."];
>
> NSString *didChange = [_infoField string];
>    NSRange r = [didChange rangeOfString:@"something"];
>    [_infoField needsDisplay];
>    if (r.location !=NSNotFound) {
>        NSLog(@"hit sleep");
>        sleep(5);
>    }
>    [_mySpinner stopAnimation:nil];
>
>
> Putting the _infoField setString call before the spinner's startAnimation call makes no difference. What am I doing wrong?
>

-needsDisplay schedules a view’s -drawRect: for the next pass through the runloop. You’re putting your process to sleep at the OS level, so the runloop is suspended along with everything else.

What you posted is evidently a minimal case, and maybe, instead of sleep(), your lengthy method is called instead. Same principle: Unless that method runs asynchronously (or simulates asynchrony by doing its work piecewise on an NSTimer, or by periodically sending -runMode:beforeDate: to the runloop), the runloop never has the chance to dispatch view updates.

	— F


_______________________________________________

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: updating NSTextField before spinner animates
      • From: sqwarqDev <email@hidden>
References: 
 >updating NSTextField before spinner animates (From: sqwarqDev <email@hidden>)

  • Prev by Date: Re: NSImage glowing
  • Next by Date: Re: How to obtain paths of laid-out text
  • Previous by thread: updating NSTextField before spinner animates
  • Next by thread: Re: updating NSTextField before spinner animates
  • Index(es):
    • Date
    • Thread