Search code examples
iosobjective-cjtcalendar

JTcalendar - How to use the method (BOOL)haveTaskForDay:(NSDate*)date


I'm using JTCalendar in my project. I've to show indicators (round dots) under dates if an event for that day is available. Response from the API gives me an array of dictionaries. Dictionary has a key "service_date" and value in string like "10/02/2017".

How can i use the method haveTaskForDay to check service dates?


Solution

  • In JTCalendar's delegate:

    - (void)calendar:(JTCalendarManager *)calendar prepareDayView:(JTCalendarDayView *)dayView
    {
    
                if([self haveTaskForDay:dayView.date])
                {
                    dayView.dotView.hidden = NO;
                    dayView.dotView.backgroundColor = [UIColor blackColor];
                }
                else
                {
                    dayView.dotView.hidden = YES;
                }
    }
    

    and in your haveTaskForDay method, you will get date parameter from above delegate then you can check if date is similar with the one in your dictionary:

    - (BOOL) haveTaskForDay :(NSDate *)date
    {
     for (NSDictionary * eventDictionary in yourArray)
            {
                NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
                [formatter setDateFormat:@"dd/MM/yyyy"];
                NSString * calendarDate = [formatter stringFromDate:date];
    
                NSString * dateString = [eventDictionary objectForKey : @"service_date"];
    
                if([dateString isEqualToString:calendarDate])
                    return 1;
            }
    
        }
            return 0;
    }
    

    Note: I did not run this code. You should make corrections if necessary.