我正在使用项目中的日历视图。我正在使用mbcalendarkit。单个事件显示的时间日期。但是我希望在多个事件显示中单一日期。但是如何可能会提供帮助。
- (void) viewWillAppear: (BOOL)animated{
NSArray *title = [_caldevice valueForKey:@"pill"];
// NSLog(@"event name fetch %@",title);
NSArray *date =[_caldevice valueForKey:@"datetaken"];
// NSLog(@"event fetch %@",date);
NSArray*dose= [_caldevice valueForKey:@"dose"];
NSString *title1;
NSString*title2;
NSDate *date1;
NSData *imgdata;
CKCalendarEvent *releaseUpdatedCalendarKit;
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"dd-MM-yyyy";
for (int i = 0; i < [date count]; i++){
title1 = NSLocalizedString(title[i], @"");
title2 = NSLocalizedString(dose[i], @"");
NSString *combined = [NSString stringWithFormat:@"%@ - %@", title1, title2];
date1 = [dateFormatter dateFromString:date[i]];
releaseUpdatedCalendarKit = [CKCalendarEvent eventWithTitle:combined andDate:date1 andInfo:Nil];
// NSLog(@"Event: %@ , %@",combined,date1);
// releaseUpdatedCalendarKit = [CKCalendarEvent eventWithTitle:combined andDate:date1 andInfo:Nil andColor:[UIColor blueColor]];
self.data[date1] = @[releaseUpdatedCalendarKit];
}
}
您在一堆事件上循环,对于每个事件,您都用新的数组替换了一个包含一个元素的先前分配的数组。
替换此:
self.data[date1] = @[releaseUpdatedCalendarKit];
更类似这样的东西:
// 1. First, get the previous events for that day.
NSMutableArray <CKCalendarEvent *> *events = self.data[date1].mutableCopy;
// 2. If events exist, append the event, otherwise create an empty array with the new event.
if (events) {
[events addObject: newEvent];
}
else {
events = @[newEvent];
}
// 3. Set the events for the date key.
self.data[date1] = events;
这样,您就可以执行"添加或创建"操作,而不是每次覆盖。
披露:我写并维护mbcalendarkit。