【发布时间】:2013-10-26 14:49:04
【问题描述】:
我创建了一个简单的按钮游戏,每次点击按钮都会给用户一个分数。该按钮每 1.5 秒随机出现在屏幕上。我希望游戏在 30 秒或 20 个随机按钮弹出后结束。我一直在使用下面的代码在屏幕上随机弹出按钮:
timer = [NSTimer scheduledTimerWithTimeInterval: 1.5 target:self
selector:@selector(moveButton:)
userInfo:nil
repeats:YES];
我已经在头文件中声明了定时器:
NSTimer *timer;
@property (nonatomic, retain) NSTimer *timer;
我在Using Timers 上阅读了 Apple Docs,但未能完全理解。我想也许我可以使用:
- (void)countedTimerFireMethod:(NSTimer *)timer{
count ++;
if(count > 20){
[self.timer invalidate];
self.timer = nil;
但它不能正常工作。我究竟做错了什么?我是 Objective-C 的新手,所以我对事情的工作原理不是很熟悉。
【问题讨论】:
-
计数在哪里声明?您是否在计数上设置了断点以查看每次调用是什么?
-
你能定义“不能正常工作”吗?你看到了什么你不想要的行为?
标签: ios objective-c nstimer