【发布时间】:2013-03-19 22:05:21
【问题描述】:
我有一个真正奇怪的 NSTimer 对象行为。
我正在尝试以 2 秒的重复计数调用 ChangePic 方法,但计时器没有重复。我有这个问题仅在项目中的 1 个班级
我的应用中有 5 个视图控制器,除了这个之外,相同的代码适用于所有类。 有人知道怎么可能吗?有没有可能是什么东西阻塞了计时器?
-BTW,ChangePic 方法只调用一次,不重复。
我的代码:
ViewController.h
@property (nonatomic, strong) NSTimer *timer;
ViewController.m
_timer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(ChangePic) userInfo:nil repeats:YES];
[_timer fire];
-(void) ChangePic {
NSLog(@"testing");
}
【问题讨论】:
-
我将代码完全复制并粘贴到项目中,并且运行良好。你应该搜索我认为的代码其他部分的错误
-
P.S.无需拨打
fire,定时器会立即启动。 -
我不认为问题出在您发布的代码中。看看别处。 ChangePic() 是触发一次还是根本不触发?
标签: ios objective-c nstimer repeat