我怎样才能做一个计时器,从3倒计时,然后运行一个方法?我会怎么做?可可触摸 - 定时器
1
A
回答
2
更好的办法可能是使用performSelector:withObject:afterDelay:
方法:
[self performSelector:@selector(myMethod) withObject:nil afterDelay:3.0f];
或者如果方法需要1个参数:
[self performSelector:@selector(myMethod:) withObject:parameter afterDelay:3.0f];
如果方法有多个参数,您需要使用NSInvocation
类
3
与计数从0到3的计时器不同吗?无论如何,它仍然会等待三秒钟。
[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(myMethod:) userInfo:nil repeats:NO];
1
- (void) handleTimer: (NSTimer *) timer
{
do some work here...
} // handleTimer
// at some point in your controller
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 3.0
target: self
selector: @selector(handleTimer:)
userInfo: nil
repeats: NO];
相关问题
- 1. 可可触摸 - 用定时器动画
- 2. 可可触摸 - 倒数计时器
- 3. 可可触摸 - 在UIImageView中触摸
- 4. 可可触摸:动画上的触摸
- 5. 可可触摸 - AVFoundation
- 6. 可可触摸NStimer问题
- 7. 可可触摸视图控制器
- 8. 可可触摸和SQL服务器
- 9. 使用自定义UISlider - 可可触摸
- 10. 可可触摸 - 自定义的UILabel
- 11. 可可触摸 - 时间按钮按下
- 12. 可可触摸 - 视图
- 13. “可可触摸静态库”
- 14. 可可触摸UITableView数据
- 15. 可可触摸 - 加载AVAudioPlayer
- 16. 可可触摸 - 对话框?
- 17. XML与可可触摸
- 18. 可可触摸 - UITextView颜色
- 19. 可可触摸NSRegularExpression模式
- 20. 迁移可可触摸项目可可
- 21. iPhone SDK使按钮不可触摸/可触摸
- 22. 可可触摸视图/视图控制器约定
- 23. 可可触摸 - 用触摸点绘制核心图形
- 24. 在可可触摸中实现基于触摸的旋转
- 25. 可可触摸 - 内存管理
- 26. 触摸IOS中的视图时可以触摸点吗?
- 27. 可可触摸:装饰文字
- 28. 可可触摸 - 设置触摸的最大数量
- 29. 可可触摸:UITableView不调整
- 30. 嵌套的可可触摸框架
我选择这个作为acepted答案,因为它需要最少的代码。 :] – user377419 2010-08-06 14:43:46
请注意,如果您希望在延迟过去之前取消或停止执行选择器,则可能需要查看下面slf的答案。 – Etienne 2013-10-14 06:15:44