• 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
while loop with sleep(): logging works, but not UI events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

while loop with sleep(): logging works, but not UI events


  • Subject: while loop with sleep(): logging works, but not UI events
  • From: Daniel Richman <email@hidden>
  • Date: Fri, 27 Jun 2008 20:55:45 -0700

Hi All,

I'm trying to program a simple timer app: you enter a number of seconds, and it updates a text field every second with the number of secs remaining. The problem is that I'm not able to do anything with the UI while this is going on. Here's my code:

- (IBAction)startTimer:(id)sender
{
[startButton setState:NSOffState];
int timeInSeconds = [((NSNumber *)[inTextField objectValue]) intValue];
while (timeInSeconds > 0) {
[outTextField setStringValue:[NSString stringWithFormat:@"%d more second(s) to go", timeInSeconds]];
sleep(1);
timeInSeconds--;
}
[outTextField setStringValue:@"Finished timing"];
NSBeep();
}


What's happening is that if I enter a number and then press 'start', 'start' stays in the 'pressed' position until the loop finishes, after which it returns to the normal position. My guess is that this is stopping any other UI events from occurring. This would also explain why I'm able to log a message each time the loop iterates.

But I'm still not sure why the button is staying pressed. Thoughts, anyone?

Daniel
_______________________________________________

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: while loop with sleep(): logging works, but not UI events
      • From: "Stephen J. Butler" <email@hidden>
    • Re: while loop with sleep(): logging works, but not UI events
      • From: "Shawn Erickson" <email@hidden>
  • Prev by Date: Re: NSString uppercaseString
  • Next by Date: Re: while loop with sleep(): logging works, but not UI events
  • Previous by thread: How can I find the source of random crashes when using debug frameworks
  • Next by thread: Re: while loop with sleep(): logging works, but not UI events
  • Index(es):
    • Date
    • Thread