我是Iphone编程新手我想了解如何在Xcode Iphonesdk中创建NSTimer。谁能建议我?
答案 0 :(得分:3)
NSTimer *timer = [NSTimer scheduleTimerWithTimeInterval:TIME_INTERVAL target:self selector:@selector(YOUR_METHOD_NAME) userInfo:nil repeats:YES/NO];
希望这会对你有帮助........
答案 1 :(得分:0)
以下是添加NSTimer的代码..
1) in .h file
NSTimer *timer;
2) in .m file
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(YOUR_METHOD_NAME) userInfo:nil repeats:YES];
注意::所以你的方法会在每1秒钟后连续调用..如果你想调用计时器方法只设置一次重复:NO ...
使计时器无效
3) to invalidate the timer where you want..
[timer invalidate];