Reputation: 2992
I'm trying to develop a new application for iOS
but I'm stuck with NSTimer
:-(. Currently I have a void
function which hides an UIButton
after the user taps twice or more on the screen and a NSTimer
. I want to make the button visible again after the NSTimer
reaches 5 seconds and stop and reset it right after in order to re-hide it after the user taps twice again :-) but I don't know how to tell the app that 5 seconds have passed :-/.
Can someone help me, please? :-)
Here's the code so far :-)
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSUInteger numTaps = [[touches anyObject] tapCount];
if (numTaps >= 2)
{
// Other code//
[self.button setHidden:YES];
buttonHideTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 invocation:nil repeats:NO];
// Other code //
}
}
Thanks!
Upvotes: 0
Views: 486
Reputation: 1299
The timer needs to have a selector, which will tell the timer what to do after the time has passed:
buttonHideTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(showButtonNow) userInfo:nil repeats:NO];
Upvotes: 3