我有一個奇怪的問題。沒有CFRunLoop,我的NSTimer CallMe方法不會被觸發。如果我添加CFRunLoop,則CFRunLoop之後的行永遠不會被調用。我想要CFRunLoop和CallMe方法之後的行都被觸發。NSTimer與CFRunLoop
編輯 - 我不在乎CFRunLoop只是想讓計時器每20秒觸發一次。
我添加的代碼及以下
int main(int argc, char * const argv[]) {
Updater *theUpdater = [[Updater alloc] init];
NSTimer *theTimer = [theUpdater getTimer];
[theTimer retain];
//CFRunLoopRun();
NSLog(@"I am here"); //If I uncomment CFRUnLoop this line does not get executed
}
@implementation更新
- (NSTimer *)getTimer {
NSLog(@"Timer started");
NSTimer *theTimer;
theTimer = [NSTimer scheduledTimerWithTimeInterval:20.0
target:self
selector:@selector(CallMe:)
userInfo:nil
repeats:YES];
return theTimer;
}
-(void) CallMe:(NSTimer*)theTimer{
NSLog(@"I Never get called");
}
@end