任何人都可以帮助我解决我遇到的问题吗?
我正在使用 Tapku 日历库日视图来显示事件。首次加载日历时,事件会正确显示。如果我将日期更改为昨天或明天,则日历不会显示事件。
我已经实现了以下事件。
- (void)calendarDayTimelineView:(TKCalendarDayView *)calendarDay didMoveToDate:(NSDate *)date
{
//Here is my logic to pull the data from db server.
//After this I am calling the method below.
[self.dayView reloadData];
}
- (NSArray *) calendarDayTimelineView:(TKCalendarDayView*)calendarDayTimeline eventsForDate:(NSDate *)eventDate{
self.myAppointments = nil;
NSFetchRequest *fetchRequest = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription
entityForName:@"Tasks" inManagedObjectContext:self.managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
self.myAppointments = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
if([eventDate compare:[NSDate dateWithTimeIntervalSinceNow:-24*60*60]] == NSOrderedAscending) return @[];
if([eventDate compare:[NSDate dateWithTimeIntervalSinceNow:24*60*60]] == NSOrderedDescending) return @[];
NSDateComponents *info = [[NSDate date] dateComponentsWithTimeZone:calendarDayTimeline.timeZone];
info.second = 0;
NSMutableArray *ret = [NSMutableArray array];
for(Tasks *apt in self.myAppointments){
TKCalendarDayEventView *event = [calendarDayTimeline dequeueReusableEventView];
if(event == nil) event = [TKCalendarDayEventView eventView];
event.identifier = nil;
event.titleLabel.text = apt.task_subject;
if ( [allTrim(apt.location) length] != 0 )
{
event.locationLabel.text = apt.location;
}
NSDate *startDate = apt.task_start;
NSDate *endDate = apt.task_end;
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:startDate];
NSInteger hour = [components hour];
NSInteger minute = [components minute];
info.hour = hour;
info.minute = minute;
event.startDate = [NSDate dateWithDateComponents:info];
components = [calendar components:(NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:endDate];
hour = [components hour];
minute = [components minute];
info.hour = hour;
info.minute = minute;
event.endDate = [NSDate dateWithDateComponents:info];
[ret addObject:event];
}
return ret;
}
我已经调试了代码,数据被分配给事件,但是我无法查看日历上的任何内容。
请..帮助解决这个问题。
问候,
gvnsandeep