嗨,我正在尝试在特定日期做某事,目前我只是记录一些随机的东西,但日志在应用程序启动时直接出现,而不是在我设置的日期。这是我的代码。
-(void)theMagicDate{
NSCalendar *nextCal = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *nextComp = [nextCal components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];
[nextComp setYear:2013];
[nextComp setMonth:3];
[nextComp setDay:26];
[nextComp setHour:10];
[nextComp setMinute:05];
UIDatePicker *nextDay = [[UIDatePicker alloc]init];
[nextDay setDate:[nextCal dateFromComponents:nextComp]];
if(nextDay.date){
NSLog(@"Doing the stuff on the date");
}
}
我从 viewDidLoad 调用这个函数