2014-03-27 52 views

回答

1

SOLUTION

必須有另一種方式正如你看到解決這個問題

,在下面的方法:

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.title = NSLocalizedString(@"Day View", @""); 


    self.data = @[ 
     @[@"Meeting with five random dudes", @"Five Guys", @48, @0, @50, @30], 
     @[@"Unlimited bread rolls got me sprung", @"Olive Garden", @-24, @0, @-22, @0], 
     @[@"Appointment", @"Dennys", @15, @0, @18, @0], 
     @[@"Turkey Time...... oh wait", @"Chick-fela", @14, @0, @19, @0]]; 
} 

self.data被加載。

請注意,沒有方法將事件添加到特定的日期。但是我們可以添加一個這樣的事件:@[@"Meeting with five random dudes", @"Five Guys", @48, @0, @50, @30]在這個@48意味着事件在後天

@[@"Unlimited bread rolls got me sprung", @"Olive Garden", @-24, @0, @-22, @0]在此@-24表示事件是在今天(昨天)之前的

因此,首先您應該使用以下代碼計算特定日期之間的時間間隔。

- (NSArray *)getTimeFromNow:(NSDate *)startDate endDateTime:(NSDate *)endDate 
{ 
    NSDate *todayDate = [NSDate date]; 
    NSTimeInterval startFromNowSeconds = [startDate timeIntervalSinceDate:todayDate]; 
    NSTimeInterval endFromNowSeconds = [endDate timeIntervalSinceDate:todayDate]; 

    NSNumber *startHour = [NSNumber numberWithInt:startFromNowSeconds/(60 * 60)]; 
    NSNumber *startMinute = [NSNumber numberWithInt:startFromNowSeconds/60 - startHour.intValue * 60]; 

    NSNumber *endHour = [NSNumber numberWithInt:endFromNowSeconds/(60 * 60)]; 
    NSNumber *endMinute = [NSNumber numberWithInt:endFromNowSeconds/60 - endHour.intValue * 60]; 

    return @[startHour, startMinute, endHour, endMinute]; 
} 

下面的代碼應該說:

//if([eventDate compare:[NSDate dateWithTimeIntervalSinceNow:-24*60*60]] == NSOrderedAscending) return @[]; 
//if([eventDate compare:[NSDate dateWithTimeIntervalSinceNow:24*60*60]] == NSOrderedDescending) return @[]; 
相關問題