如何在目标C中的Web服务的日历上显示同一date的3个事件

我是iOS的新手,我面临着在同一天显示多个事件的问题。我正在使用JTCalendar。

我的代码是这样的

在ViewDidLoad中

_calendarManager = [JTCalendarManager new]; _calendarManager.delegate = self; [self createMinAndMaxDate]; [_calendarManager setMenuView:_calendarMenuView]; [_calendarManager setContentView:_calendarContentView]; [_calendarManager setDate:_todayDate]; 

在viewWillAppear我编码改变颜色根据Web服务

 [self serverconnectionScheduleAudit]; [self serverconnectionScheduleKPI]; [self serverconnectionScheduleMeeting]; #pragma mark - CalendarManager delegate - (void)calendar:(JTCalendarManager *)calendar prepareDayView:(JTCalendarDayView *)dayView { // Today if([_calendarManager.dateHelper date:[NSDate date] isTheSameDayThan:dayView.date]){ dayView.circleView.hidden = NO; dayView.circleView.backgroundColor = [UIColor blueColor]; dayView.dotView.backgroundColor = [UIColor whiteColor]; dayView.textLabel.textColor = [UIColor whiteColor]; } // Selected date else if(_dateSelected && [_calendarManager.dateHelper date:_dateSelected isTheSameDayThan:dayView.date]){ if([CheckString isEqualToString:@"0"]) { dayView.circleView.hidden = NO; dayView.circleView.backgroundColor = [UIColor redColor]; dayView.dotView.backgroundColor = [UIColor whiteColor]; dayView.textLabel.textColor = [UIColor whiteColor]; } else if ([CheckString isEqualToString:@"1"]) { dayView.circleView.hidden = NO; dayView.circleView.backgroundColor = [UIColor orangeColor]; dayView.dotView.backgroundColor = [UIColor whiteColor]; dayView.textLabel.textColor = [UIColor whiteColor]; } else if ([CheckString isEqualToString:@"2"]) { dayView.circleView.hidden = NO; dayView.circleView.backgroundColor = [UIColor greenColor]; dayView.dotView.backgroundColor = [UIColor whiteColor]; dayView.textLabel.textColor = [UIColor whiteColor]; } } // Other month else if(![_calendarManager.dateHelper date:_calendarContentView.date isTheSameMonthThan:dayView.date]){ if([CheckString isEqualToString:@"0"]) { dayView.circleView.hidden = YES; dayView.dotView.backgroundColor = [UIColor redColor]; dayView.textLabel.textColor = [UIColor lightGrayColor]; } else if ([CheckString isEqualToString:@"1"]) { dayView.circleView.hidden = YES; dayView.dotView.backgroundColor = [UIColor orangeColor]; dayView.textLabel.textColor = [UIColor lightGrayColor]; } else if ([CheckString isEqualToString:@"2"]) { dayView.circleView.hidden = YES; dayView.dotView.backgroundColor = [UIColor greenColor]; dayView.textLabel.textColor = [UIColor lightGrayColor]; } } // Another day of the current month else{ if([CheckString isEqualToString:@"0"]) { dayView.circleView.hidden = YES; dayView.dotView.backgroundColor = [UIColor redColor]; dayView.textLabel.textColor = [UIColor blackColor]; } else if ([CheckString isEqualToString:@"1"]) { dayView.circleView.hidden = YES; dayView.dotView.backgroundColor = [UIColor orangeColor]; dayView.textLabel.textColor = [UIColor blackColor]; } else if ([CheckString isEqualToString:@"2"]) { dayView.circleView.hidden = YES; dayView.dotView.backgroundColor = [UIColor greenColor]; dayView.textLabel.textColor = [UIColor blackColor]; } } if([self haveEventForDay:dayView.date]){ dayView.dotView.hidden = NO; } else{ dayView.dotView.hidden = YES; } } - (void)calendar:(JTCalendarManager *)calendar didTouchDayView:(JTCalendarDayView *)dayView { _dateSelected = dayView.date; dayView.circleView.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.1, 0.1); [UIView transitionWithView:dayView duration:.3 options:0 animations:^{ dayView.circleView.transform = CGAffineTransformIdentity; [_calendarManager reload]; } completion:nil]; if(_calendarManager.settings.weekModeEnabled){ return; } if(![_calendarManager.dateHelper date:_calendarContentView.date isTheSameMonthThan:dayView.date]){ if([_calendarContentView.date compare:dayView.date] == NSOrderedAscending){ [_calendarContentView loadNextPageWithAnimation]; } else{ [_calendarContentView loadPreviousPageWithAnimation]; } } } #pragma mark - CalendarManager delegate - Page mangement // Used to limit the date for the calendar, optional - (BOOL)calendar:(JTCalendarManager *)calendar canDisplayPageWithDate:(NSDate *)date { return [_calendarManager.dateHelper date:date isEqualOrAfter:_minDate andEqualOrBefore:_maxDate]; } - (void)calendarDidLoadNextPage:(JTCalendarManager *)calendar { // NSLog(@"Next page loaded"); } - (void)calendarDidLoadPreviousPage:(JTCalendarManager *)calendar { // NSLog(@"Previous page loaded"); } #pragma mark - Fake data - (void)createMinAndMaxDate { _todayDate = [NSDate date]; _minDate = [_calendarManager.dateHelper addToDate:_todayDate months:-12]; _maxDate = [_calendarManager.dateHelper addToDate:_todayDate months:12]; } - (NSDateFormatter *)dateFormatter { static NSDateFormatter *dateFormatter; if(!dateFormatter){ dateFormatter = [NSDateFormatter new]; dateFormatter.dateFormat = @"dd-MM-yyyy"; } return dateFormatter; } - (BOOL)haveEventForDay:(NSDate *)date { NSString *key = [[self dateFormatter] stringFromDate:date]; if(_eventsByDate[key] && [_eventsByDate[key] count] > 0){ return YES; } return NO; } -(void)funAddEvents:(NSArray *)arrDate { _eventsByDate = [NSMutableDictionary new]; for(NSString *strDate in arrDate){ NSDateFormatter *dateformat = [[NSDateFormatter alloc] init]; [dateformat setDateFormat:@"YYYY/MM/dd"]; NSDate *myDate = [dateformat dateFromString:strDate]; NSString *key = [[self dateFormatter] stringFromDate:myDate]; if(!_eventsByDate[key]){ _eventsByDate[key] = [NSMutableArray new]; } [_eventsByDate[key] addObject:myDate]; } } 

连接方法和委托

 #pragma mark - Schedule Audit Actitvity //Connection Method and Delegate... -(void)serverconnectionScheduleAudit{ [customActivityIndicator startAnimating]; int Auditid =[Empid intValue]; NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" "<soap:Body>" "<AuditMethod xmlns=\"http://tempuri.org/\">" "<UserId>%d</UserId>" "</AuditMethod>" "</soap:Body>" "</soap:Envelope>",Auditid]; NSURL *myNSUObj=[NSURL URLWithString:ServerString]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:myNSUObj]; NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]]; [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [theRequest addValue: @"http://tempuri.org/AuditMethod" forHTTPHeaderField:@"SOAPAction"]; [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"]; [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; myNSUConnectionObjScheduleAudit=[[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; NSLog(@"Data =%@",myNSUConnectionObjScheduleAudit); if(myNSUConnectionObjScheduleAudit) { NSLog(@"successful connection"); myNSMDataFromServerScheduleAudit=[[NSMutableData alloc]init]; } } #pragma mark - Schedule Actitvity //Connection Method and Delegate... -(void)serverconnectionScheduleKPI{ int KPI =[Empid intValue]; NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" "<soap:Body>" "<KPIMethod xmlns=\"http://tempuri.org/\">" "<UserId>%d</UserId>" "</KPIMethod>" "</soap:Body>" "</soap:Envelope>",KPI]; NSURL *myNSUObj=[NSURL URLWithString:ServerString]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:myNSUObj]; NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]]; [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [theRequest addValue: @"http://tempuri.org/KPIMethod" forHTTPHeaderField:@"SOAPAction"]; [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"]; [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; myNSUConnectionObjScheduleKPI=[[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; NSLog(@"Data =%@",myNSUConnectionObjScheduleKPI); if(myNSUConnectionObjScheduleKPI) { NSLog(@"successful connection"); myNSMDataFromServerScheduleKPI=[[NSMutableData alloc]init]; } } #pragma mark - Schedule Actitvity //Connection Method and Delegate... -(void)serverconnectionScheduleMeeting{ int KPI =[Empid intValue]; NSString *soapMessage = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" "<soap:Body>" "<MeetingMethod xmlns=\"http://tempuri.org/\">" "<UserId>%d</UserId>" "</MeetingMethod>" "</soap:Body>" "</soap:Envelope>",KPI]; NSURL *myNSUObj=[NSURL URLWithString:ServerString]; // NSURLRequest *myNSURequestObj=[NSURLRequest requestWithURL:myNSUObj]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:myNSUObj]; NSString *msgLength = [NSString stringWithFormat:@"%lu", (unsigned long)[soapMessage length]]; [theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"]; [theRequest addValue: @"http://tempuri.org/MeetingMethod" forHTTPHeaderField:@"SOAPAction"]; [theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"]; [theRequest setHTTPMethod:@"POST"]; [theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]]; myNSUConnectionObjScheduleMeeting=[[NSURLConnection alloc]initWithRequest:theRequest delegate:self]; NSLog(@"Data =%@",myNSUConnectionObjScheduleMeeting); if(myNSUConnectionObjScheduleMeeting) { NSLog(@"successful connection"); myNSMDataFromServerScheduleMeeting=[[NSMutableData alloc]init]; } } - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ if(connection == myNSUConnectionObjScheduleAudit) { loginStatusScheduleAudit = [[NSString alloc] initWithBytes: [myNSMDataFromServerScheduleAudit mutableBytes] length:[myNSMDataFromServerScheduleAudit length] encoding:NSUTF8StringEncoding]; NSLog(@"loginStatus =%@",loginStatusScheduleAudit); NSError *parseError = nil; NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:loginStatusScheduleAudit error:&parseError]; NSLog(@"JSON DICTIONARY = %@",xmlDictionary); recordResultScheduleAudit = [xmlDictionary[@"success"] integerValue]; NSLog(@"Success: %ld",(long)recordResultScheduleAudit); NSDictionary* Address=[xmlDictionary objectForKey:@"soap:Envelope"]; NSLog(@"Address Dict = %@",Address); NSDictionary *new =[Address objectForKey:@"soap:Body"]; NSLog(@"NEW DICT =%@",new); NSDictionary *LoginResponse=[new objectForKey:@"Get_Audits_Schedules_UserResponse"]; NSLog(@"Login Response DICT =%@",LoginResponse); NSDictionary *LoginResult=[LoginResponse objectForKey:@"Get_Audits_Schedules_UserResult"]; NSLog(@"Login Result =%@",LoginResult); if(LoginResult.count>0) { NSLog(@"Login Result = %@",LoginResult); NSLog(@"Login Result Dict =%@",LoginResult); NSString *teststr =[[NSString alloc] init]; teststr =[LoginResult objectForKey:@"text"]; NSLog(@"Test String Value =%@",teststr); NSString *string = [LoginResult valueForKey:@"text"]; NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; responsedictScheduleAudit = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; ScheduleDatearrayScheduleAudit=[[NSMutableArray alloc] init]; ScheduleDatearrayScheduleAudit =[responsedictScheduleAudit valueForKey:@"StartDate"]; CheckString=@"0"; [self funAddEvents:EndDatearrayScheduleAudit]; } } if(connection == myNSUConnectionObjScheduleKPI) { loginStatusScheduleKPI = [[NSString alloc] initWithBytes: [myNSMDataFromServerScheduleKPI mutableBytes] length:[myNSMDataFromServerScheduleKPI length] encoding:NSUTF8StringEncoding]; NSLog(@"loginStatus =%@",loginStatusScheduleKPI); NSError *parseError = nil; NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:loginStatusScheduleKPI error:&parseError]; NSLog(@"JSON DICTIONARY = %@",xmlDictionary); recordResultScheduleKPI = [xmlDictionary[@"success"] integerValue]; NSLog(@"Success: %ld",(long)recordResultScheduleKPI); NSDictionary* Address=[xmlDictionary objectForKey:@"soap:Envelope"]; NSLog(@"Address Dict = %@",Address); NSDictionary *new =[Address objectForKey:@"soap:Body"]; NSLog(@"NEW DICT =%@",new); NSDictionary *LoginResponse=[new objectForKey:@"Get_Kpi_Schedules_UserResponse"]; NSLog(@"Login Response DICT =%@",LoginResponse); NSDictionary *LoginResult=[LoginResponse objectForKey:@"Get_Kpi_Schedules_UserResult"]; NSLog(@"Login Result =%@",LoginResult); if(LoginResult.count>0) { NSLog(@"Login Result = %@",LoginResult); NSLog(@"Login Result Dict =%@",LoginResult); NSString *teststr =[[NSString alloc] init]; teststr =[LoginResult objectForKey:@"text"]; NSLog(@"Test String Value =%@",teststr); NSString *string = [LoginResult valueForKey:@"text"]; NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; responsedictScheduleKPI = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; StartDatearrayScheduleKPI =[[NSMutableArray alloc] init]; StartDatearrayScheduleKPI =[responsedictScheduleKPI valueForKey:@"StartDate"]; CheckString=@"1"; [self funAddEvents:EndDatearrayScheduleKPI]; } } if(connection == myNSUConnectionObjScheduleMeeting) { loginStatusScheduleMeeting = [[NSString alloc] initWithBytes: [myNSMDataFromServerScheduleMeeting mutableBytes] length:[myNSMDataFromServerScheduleMeeting length] encoding:NSUTF8StringEncoding]; NSLog(@"loginStatus =%@",loginStatusScheduleMeeting); NSError *parseError = nil; NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:loginStatusScheduleMeeting error:&parseError]; NSLog(@"JSON DICTIONARY = %@",xmlDictionary); recordResultScheduleMeeting = [xmlDictionary[@"success"] integerValue]; NSLog(@"Success: %ld",(long)recordResultScheduleMeeting); NSDictionary* AddressDict=[xmlDictionary objectForKey:@"soap:Envelope"]; NSLog(@"Address Dict = %@",AddressDict); NSDictionary *new =[AddressDict objectForKey:@"soap:Body"]; NSLog(@"NEW DICT =%@",new); NSDictionary *LoginResponse=[new objectForKey:@"Get_Meeting_Schedules_UserResponse"]; NSLog(@"Login Response DICT =%@",LoginResponse); NSDictionary *LoginResult=[LoginResponse objectForKey:@"Get_Meeting_Schedules_UserResult"]; NSLog(@"Login Result =%@",LoginResult); if(LoginResult.count>0) { NSLog(@"Login Result = %@",LoginResult); NSLog(@"Login Result Dict =%@",LoginResult); NSString *teststr =[[NSString alloc] init]; teststr =[LoginResult objectForKey:@"text"]; NSLog(@"Test String Value =%@",teststr); NSString *string = [LoginResult valueForKey:@"text"]; NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; responsedictScheduleMeeting = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; StartDatearrayScheduleMeeting =[[NSMutableArray alloc] init]; StartDatearrayScheduleMeeting =[responsedictScheduleMeeting valueForKey:@"StartDate"]; CheckString=@"2"; [self funAddEvents:EndDatearrayScheduleMeeting]; } } NSMutableArray *arrDates=[[NSMutableArray alloc] init]; [arrDates addObjectsFromArray:StartDatearrayScheduleKPI]; [arrDates addObjectsFromArray:ScheduleDatearrayScheduleAudit]; [arrDates addObjectsFromArray:StartDatearrayScheduleMeeting]; [self funAddEvents:arrDates]; [customActivityIndicator stopAnimating]; } #pragma mark - NSXMLParsing Delegate -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict { if([elementName isEqualToString:@"FillBlocksNew"]) { myDataClassObjScheduleAudit=[[mydata alloc]init]; } } -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string { myMutableStringObjScheduleAudit=[[NSMutableString alloc]initWithString:string]; NSLog(@"Array String: %@",myMutableStringObjScheduleAudit); NSData *dataAudit = [myMutableStringObjScheduleAudit dataUsingEncoding:NSUTF8StringEncoding]; responsedictScheduleAudit = [NSJSONSerialization JSONObjectWithData:dataAudit options:0 error:nil]; NSLog(@"JSON DATA = %@",responsedictScheduleAudit); myMutableStringObjScheduleKPI=[[NSMutableString alloc]initWithString:string]; NSLog(@"Array String: %@",myMutableStringObjScheduleKPI); NSData *dataKPI = [myMutableStringObjScheduleKPI dataUsingEncoding:NSUTF8StringEncoding]; responsedictScheduleKPI = [NSJSONSerialization JSONObjectWithData:dataKPI options:0 error:nil]; NSLog(@"JSON DATA = %@",responsedictScheduleKPI); myMutableStringObjScheduleMeeting=[[NSMutableString alloc]initWithString:string]; NSLog(@"Array String: %@",myMutableStringObjScheduleMeeting); NSData *dataMeeting = [myMutableStringObjScheduleMeeting dataUsingEncoding:NSUTF8StringEncoding]; responsedictScheduleMeeting = [NSJSONSerialization JSONObjectWithData:dataMeeting options:0 error:nil]; NSLog(@"JSON DATA = %@",responsedictScheduleMeeting); } 

这是我如何展示

在这里输入图像说明

我需要在图像中显示像这样的多个事件 在这里输入图像说明

我需要在JTCalendar的同一date,在Web服务和不同的颜色显示2,3个事件。如何做到这一点,任何人都可以尝试这样的。感谢提前!