NSTimer选择器不重复

时间:2013-04-26 21:16:43

标签: ios cocoa-touch nstimer appdelegate

AppDelegate我定义了

AppDelegate.h

@property (strong, nonatomic) NSTimer *notificationTimer;

AppDelegate.m

@synthesize notificationTimer = _notificationTimer;

- (void)applicationDidBecomeActive:(UIApplication *)application {
    NSLog(@"applicationDidBecomeActive");
    self.notificationTimer = [NSTimer timerWithTimeInterval:5
                                                     target:self
                                                   selector:@selector(checkForNotifications:)
                                                   userInfo:nil
                                                    repeats:YES];
    [self.notificationTimer fire];
}

checkForNotifications:达到一次但从不重复。为什么呢?

1 个答案:

答案 0 :(得分:2)

使用:
self.notificationTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(checkForNotifications) userInfo:nil repeats:YES];