when user click on particular date a alert will show with that event title

老子叫甜甜 提交于 2019-12-09 01:56:30

From what I see in the question. In understood it as follows. You need to compare the selected date in calendar with dates given in json. If it matches, then you have to show the alert. For that, you need to compare the selected date with dates given in Json.

Inside the function,

-(void) SACalendar:(SACalendar*)calendar didSelectDate:(int)day month:(int)month year:(int)year
{

   NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];          
   dateFormatter.dateFormat = @"yyyy-MM-dd";
   dateFormatter.timeZone = [NSTimeZone systemTimeZone];

    for(int i=0; i < EventArray.count; i++)
    {
        NSString *eventStartString = [[EventArray objectAtIndex:i] objectForKey:@"event_start"];
        NSString *eventEndString = [[EventArray objectAtIndex:i]objectForKey:@"event_end"];

        if(eventStartString != nil && eventEndString != nil)
        {// s_ -> start; e_ -> end;
            eventStartString = [eventStartString substringToIndex:10];
            eventEndString = [eventEndString substringToIndex:10];

            NSDate *s_date = [dateFormatter dateFromString:eventStartString];
            NSDate *e_date = [dateFormatter dateFromString:eventEndString]

            NSCalendar *myCalendar = [NSCalendar currentCalendar];

            long s_day = [myCalendar component:NSCalendarUnitDay fromDate:s_date];
            long s_month = [myCalendar component:NSCalendarUnitMonth fromDate:s_date];
            long s_year = [myCalendar component:NSCalendarUnitYear fromDate:s_date];

            long e_day = [myCalendar component:NSCalendarUnitDay fromDate:e_date];
            long e_month = [myCalendar component:NSCalendarUnitMonth fromDate:e_date];
            long e_year = [myCalendar component:NSCalendarUnitYear fromDate:e_date];

            eventtitlestring = [[EventArray objectAtIndex:i] objectForKey:@"title"];

            if ((day == (int)s_day) && (month == (int)s_month) && (year == (int)s_year)) {
                UIAlertView *showevent = [[UIAlertView alloc]initWithTitle:@"Alert" message:self.eventtitlestring delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                [showevent show];
                return;
            }else if ((day == (int)e_day) && (month == (int)e_month) && (year == (int)e_year)) {
                UIAlertView *showevent = [[UIAlertView alloc]initWithTitle:@"Alert" message:self.eventtitlestring delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
                [showevent show];
                return;
            }
        }
    }        
}

After extracting month, day, year, you can compare them and accordingly show the event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!