可能重複:
NSTimer timerWithTimeInterval: not working的NSTimer不重複預期
在我的應用程序,我有以下設置來運行具有的NSTimer一個動作:在M
。文件:
@implementation MYViewController {
NSTimer *aTimer;
}
比,當用戶點擊相關按鈕,我有:
- (IBAction)userClick:(id)sender {
aTimer = [NSTimer timerWithTimeInterval:1.0
target:self
selector:@selector(doSomethingWithTimer:)
userInfo:nil
repeats:YES];
//[aTimer fire]; //NSTimer was fired just once.
}
我也有:
-(void)doSomethingWithTimer:(NSTimer*)timer {
NSLog(@"something to be done");
}
我希望有在領事一行每秒鐘說「要做的事情」。計時器甚至不會被調用一次。我已經嘗試使用[aTimer fire]發射NSTimer,但它只發射一次,並沒有像我預期的那樣重複。
任何人都可以指導我如何處理這個?
請檢查我的問題http://stackoverflow.com/questions/11058571/nstimer-timerwithtimeinterval-not-working –