开发者

timer in iOS not working

开发者 https://www.devze.com 2023-03-22 09:26 出处:网络
I have this code for a repeated timer in my app: (inside viewDidAppear) NSDate *date = [NSDate dateWithTimeIntervalSinceNow: 3];

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

精彩评论

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