您可以NSTimer为此使用一个。但是,首先,您需要弄清楚何时NSTimer应该触发。您可以使用NSDate,NSCalendar和NSDateComponents为此:
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *todayComponents = [calendar components:NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit fromDate:[NSDate date]];
NSDate *today = [calendar dateFromComponents:todayComponents];
// today is the start of today in the local time zone. Note that `NSLog`
// will print it in UTC, so it will only print as midnight if your local
// time zone is UTC.
NSDateComponents *oneDay = [[NSDateComponents alloc] init];
oneDay.day = 1;
NSDate *tomorrow = [calendar dateByAddingComponents:oneDay toDate:today options:0];
拥有tomorrow后,您可以设置一个在该日期触发的计时器:
NSTimer *timer = [[NSTimer alloc] initWithFireDate:tomorrow interval:0 target:self selector:@selector(tomorrowTimerDidFire:) userInfo:nil repeats:NO];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
// The run loop retains timer, so you don't need to.
并在tomorrowTimerDidFire::
- (void)tomorrowTimerDidFire:(NSTimer *)timer {
[myView setNeedsDisplay:YES];
}