• 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: UILabel updating from a button click
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: UILabel updating from a button click


  • Subject: Re: UILabel updating from a button click
  • From: Luke the Hiesterman <email@hidden>
  • Date: Sun, 21 Feb 2010 07:42:26 -0800

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@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

_______________________________________________

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

References: 
 >UILabel updating from a button click (From: Michael Davey <email@hidden>)

  • Prev by Date: UILabel updating from a button click
  • Next by Date: Re: Cocoa equivalent for 'InstallApplicationEventHandler'
  • Previous by thread: UILabel updating from a button click
  • Next by thread: call ruby scripts from objective c
  • Index(es):
    • Date
    • Thread