【发布时间】:2016-03-29 06:57:32
【问题描述】:
我有以下要求,
- 首先需要选择日期。
- 然后应用需要显示提醒选项,例如(2 周前、1 周前、3 天前等)
- 如果选择的日期是两天后,那么我需要禁用 2 周前和 1 周前选项。
以下是正在使用但无法正常工作的代码,
- (IBAction)timePicker:(id)sender {
selectedTimeRow = [sender tag];
NSDate *date2=[NSDate date];
NSDate *DaysAgo;
if (selectedTimeRow==0) {
DaysAgo = [date2 dateByAddingTimeInterval:14*24*60*60];
NSLog(@"14 days ago: %@", DaysAgo);
}else if (selectedTimeRow==1){
DaysAgo = [date2 dateByAddingTimeInterval:7*24*60*60];
NSLog(@"7 days ago: %@", DaysAgo);
}else if (selectedTimeRow==2){
DaysAgo = [date2 dateByAddingTimeInterval:3*24*60*60];
NSLog(@"3 days ago: %@", DaysAgo);
}else if (selectedTimeRow==3){
DaysAgo = [date2 dateByAddingTimeInterval:1*24*60*60];
NSLog(@"1 days ago: %@", DaysAgo);
}
NSDateFormatter *format = [[NSDateFormatter alloc] init];
format.dateFormat = @"dd/MM/yyyy";
NSString *dateNew=[format stringFromDate:DaysAgo];
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell*)[button superview];
//
NSComparisonResult result = [dateNew compare:_SavedDate];
if(result == NSOrderedAscending)
{
NSLog(@"date1 is later than date2");
cell.userInteractionEnabled=NO;
}else if (result == NSOrderedDescending) {
NSLog(@"date1 is earlier than date2");
[self calltoolrBar];
cell.userInteractionEnabled=YES;
}
else
{
NSLog(@"date1 is equal to date2");
[self calltoolrBar];
cell.userInteractionEnabled=YES;
}
}
【问题讨论】:
标签: ios nsdate nscalendar