【问题标题】:NSTimer selector not repeatingNSTimer 选择器不重复
【发布时间】:2013-04-26 21:16:42
【问题描述】:

在我的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: 被访问一次,但从不重复。为什么?

【问题讨论】:

    标签: ios cocoa-touch nstimer appdelegate


    【解决方案1】:

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

    【讨论】:

    • 我在发布这个问题的那一刻就明白了。不过,谢谢。
    猜你喜欢
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-05
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    相关资源
    最近更新 更多