OGeek|极客世界-中国程序员成长平台

标题: iphone - iOS :Call a method in specific time [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 19:20
标题: iphone - iOS :Call a method in specific time

我正在尝试在这个时候调用一个方法:00:01 AM 这是我的代码,但我找不到为什么这个代码没有调用我的方法的问题。

- (BOOL)dateNSDate *)date hourNSInteger)h minuteNSInteger)m {

    NSCalendar *calendar = [[NSCalendar alloc]initWithCalendarIdentifier:currentCalendar];

    NSDateComponents *componets = [calendar componentsNSHourCalendarUnit | NSMinuteCalendarUnit )fromDate:[NSDate date]];
    if ([componets hour ] == h && [componets minute] == m) {

        return YES;
    }
    return NO;
}



- (void)updateNewDate {

    if ([self date:[NSDate date] hour:4 minute:49]) {

        label.text = @"oyooy";
    }
}

- (void)viewDidLoad {

[self updateNewDate];
}

如果你有其他方法请告诉我。



Best Answer-推荐答案


实际上你的代码工作正常,但它需要刷新......例如你可以使用 NSTimer 刷新您的方法:

[NSTimer scheduledTimerWithTimeInterval:10 target:self selectorselector(updateNewDate) userInfo:nil repeats:YES];

关于iphone - iOS :Call a method in specific time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9211640/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4