开发者

timer in iOS not working

I have this code for a repeated timer in my app:

(inside viewDidAppear)

NSDate *date = [NSDate dateWithTimeIntervalSinceNow: 3];
NSTimer *restrictionTimer = [[NSTimer alloc] initWithFireDate: date
                                      interval: 3
                                        target: self
                                      selector:@selector(changeRestriction)
                                      userInfo:nil repeats:YES];

and

- (void) changeRestriction
{
    NSLog(@"inside !!");
}

Ho开发者_如何转开发wever, I dont see any output, any help ?


If you're using -initWithFireDate:.. you have to manually add the timer to the NSRunLoop. However you could just use +scheduledTimerWithTimeInterval:.. and it will automatically trigger.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜