user3186310
user3186310

Reputation: 149

Do something after a certain time after button clicked

I am trying to have an object disappear from the view after a certain time after a button is tapped. I'm a little confused with how to get the object to do something a certain after its tapped. I am not sure if I should use a run loop or NSTimer, and even if I know what to use Im still confused on what to do to make something happen a certain time after the button is tapped.

Upvotes: 1

Views: 348

Answers (2)

Yohan
Yohan

Reputation: 1108

You can use NStimer Also

NSTimer scheduledTimerWithTimeInterval:2.0
            target:self
            selector:@selector(afterTapped:)
            userInfo:nil
            repeats:NO];

and the create action to be done for afterTapped

-(void)afterTapped:(id)sender{

      //do something
    }

Upvotes: 1

Greg
Greg

Reputation: 25459

In your button pressed method you can use:

[self performSelector:@selector(myMethod) withObject:nil afterDelay:3];

And declare method with logic you want to run:

-(void) myMethod
{
    //TODO: your logic goes here
}

You can even pass parameter to your method if you want (withObject argument).

Upvotes: 4

Related Questions