Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I delay an event in xcode?

I am surprised I can't find this answer but for some reason can't find it for Xcode.

In my app I have an IBAction buttonPressed and it adds coins to my "coins" variable and displays it in a UILabel. I would like to make it so when the user presses the button it does not add the coins or display it in the UILabel for about 30 seconds. Is there a simple way to do this? I'm pretty new, so please explain in simple steps if possible. Thank You :)

like image 966
Herbie999 Avatar asked Nov 18 '12 00:11

Herbie999


1 Answers

It's very easy, just use performSelector:withObject:afterDelay:. You would put it in your IBAction code like this:

-(IBAction)buttonPressed:(UIButton *) sender {
[self performSelector:@selector(addCoins) withObject:nil afterDelay:30];
}

-(void)addCoins {
//put whatever code you want to happen after the 30 seconds
}
like image 127
rdelmar Avatar answered Nov 15 '22 05:11

rdelmar