Please don't use sleep() on the main thread of a UI application......
If you really want to do this, I'd suggest using an ivar or a static variable
to facilitate going through the operation using
performSelector:withObject:afterDelay:
e.g.:
static int labelLoopCounter = 10;
-(IBAction)buttonPressed
{
if (labelLoopCounter == 10)
{
labelLoopCounter = 0;
[self updateLabel];
}
}
-(void)updateLabel
{
if (labelLoopCounter < 10)
{
label.text = [stringList objectAtIndex:labelLoopCounter];
labelLoopCounter++;
[self performSelector:@selector(updateLabel) withObject:nil
afterDelay:1.0];
}
}
On Feb 21, 2010, at 7:33 AM, Michael Davey wrote:
> Hi,
>
> I have, for a bit of fun, taken my first steps out of Mac development and
> into iPhone development, and have encountered a bit of a problem.
>
> Basically, what I want to do is update a UILabel when a button is clicked in
> the view, but I want to be able to update it in intervals with different
> values. I have tried basically doing this (although this is simplified for
> the purposes of demonstration) in the IBAction for the button click event:
>
> for (int i = 0; i < 10; ++i) {
> label.text = [stringList objectAtIndex:i];
> sleep(1);
> }
>
> What happens is that I only see the last value that is set - does anyone here
> know what I should be doing to code this correctly?
>
> Mikey_______________________________________________
>
> Cocoa-dev mailing list ([email protected])
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/luketheh%40apple.com
>
> This email sent to [email protected]
_______________________________________________
Cocoa-dev mailing list ([email protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]