pskow
pskow

Reputation: 135

Perform action after delay iPhone

I have a problem. What i want to do is to click on button few times, and then update a label ONCE, but after 2 seconds delay, so if you click fast, nothing change, but when you stop, then the label updates.

Perform selector metods only create queue, so it will updates everytime button is pressed.

-(IBAction)clickButton {
    i++;
    [self updateLabel if clicking stop 3 seconds ago];
}

Upvotes: 0

Views: 253

Answers (1)

danh
danh

Reputation: 62686

[NSObject cancelPreviousPerformRequestsWithTarget:self];
// then
[self performSelector ...];

Upvotes: 3

Related Questions