我想使用NSTimer重複觸發一個方法。但該方法只觸發一次。 這裏是我的代碼NSTimer不要重複(iOS開發)
- (void)viewDidLoad
{
[super viewDidLoad];
NSDate *fireDate = [NSDate dateWithTimeIntervalSinceNow:14.0];
NSTimer *timer = [[NSTimer alloc] initWithFireDate:fireDate
interval:2
target:self
selector:@selector(xuanZhuan:)
userInfo:nil
repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSDefaultRunLoopMode];
}
-(void)xuanZhuan:(NSTimer*)theTimer
{
...
}
的xuanZhuan薄荷只火一次,不repeat.Why?如何解決?
更新: 我很抱歉,定時器工作正常,問題在於軒轅方法。我現在沒有問題。
你想在14秒後打電話給玄璇方法。對 ? – 2013-03-08 04:53:18
應該沒問題,你在軒轅內做什麼? – borrrden 2013-03-08 04:53:50
你想只打2遍或者每14秒鐘打完一遍? – 2013-03-08 04:57:43