Herbie999
Herbie999

Reputation: 315

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 :)

Upvotes: 5

Views: 8828

Answers (1)

rdelmar
rdelmar

Reputation: 104082

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
}

Upvotes: 11

Related Questions