使用NSTimer在一段时间后显示一个按钮

时间:2012-12-21 16:42:53

标签: iphone objective-c ios nstimer

我正在尝试为iOS开发一个新的应用程序,但我坚持使用NSTimer :-(。目前我有void函数隐藏了UIButton用户在屏幕上点击两次或更多次后NSTimer。我想在NSTimer达到5秒后再次显示该按钮,然后停止并立即重置该按钮以便重新隐藏在用户再次点击两次后:-)但我不知道如何告诉应用程序已经过了5秒: - /。

有人可以帮帮我吗? : - )

到目前为止,这是代码: - )

- (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 //
    }
}

谢谢!

1 个答案:

答案 0 :(得分:3)

计时器需要有一个选择器,它会告诉计时器在经过一段时间后该做什么:

buttonHideTimer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(showButtonNow) userInfo:nil repeats:NO];