0

I have googled out about how to mark date in tapku library. According to them i have code below for JSON i get, but it show mark either to whole calender or none date.

Here is my JSON

data: [
  {
    id: "2",
    repeat: "0",
    allDay: false,
    title: "All Day Event",
    start: "2014-01-01 00:00:00",
    end: "2014-01-01 00:00:00",
    rend: ""
  },
  {
    id: "3",
    repeat: "0",
    allDay: false,
    title: "Long Event",
    start: "2014-01-07 00:00:00",
    end: "2014-01-10 00:00:00",
    rend: ""
  },
  {
    id: "4",
    repeat: "0",
    allDay: false,
    title: "Repeating Event",
    start: "2014-01-09 16:00:00",
    end: "2014-01-09 16:00:00",
    rend: ""
  },
]

And here is my code.

-(NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(  NSDate*)startDate toDate:(NSDate*)lastDate{

NSMutableArray *marks = [NSMutableArray array];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd"];

for (NSDictionary *dict in APPDELEGATE.calenderDataArray) {

    NSString *startdate=[[[dict objectForKey:@"start"] componentsSeparatedByString:@" "] objectAtIndex:0];
    NSString *enddate=[[[dict objectForKey:@"end"] componentsSeparatedByString:@" "] objectAtIndex:0];
    NSArray *CalenderDays=[NSArray arrayWithObjects:
                       [NSString stringWithFormat:@"%@",startdate], nil];




    NSDate *d = startDate;

    NSString * dateStart  = [dateFormat stringFromDate:startDate];
    NSLog(@"datestart==%@",dateStart);
    NSLog(@"CalenderDays==%@",CalenderDays);
    while(YES){

        if ([CalenderDays containsObject:dateStart]) {
            [marks addObject:[NSNumber numberWithBool:YES]];
        } else {
            [marks addObject:[NSNumber numberWithBool:NO]];
        }

        NSDateComponents *info = [d dateComponentsWithTimeZone:self.monthView.timeZone];
        info.day++;
        d = [NSDate dateWithDateComponents:info];
        if([d compare:lastDate]==NSOrderedDescending) break;
    }


}

NSLog(@"MarkArray %@",marks); //marks null value
return [NSArray arrayWithArray:marks];


}

I want to show date from JSON to tapku calender.

But i didn't get success.

Cactus
  • 27,075
  • 9
  • 69
  • 149

1 Answers1

0

Here is the method name: calendarMonthView: marksFromDate toDate

So create an array which contains all those NSDate objects, which required to be marked, then call this method for all those dates (either in for-loop).

Here is the reference:

https://github.com/devinross/tapkulibrary/blob/master/src/TapkuLibrary/TKCalendarMonthView.h

/** A data source that will correspond to marks for the calendar month grid for a particular month. @param monthView The calendar month grid. @param startDate The first date shown by the calendar month grid. @param lastDate The last date shown by the calendar month grid. @return Returns an array of NSNumber objects corresponding the number of days specified in the start and last day parameters. Each NSNumber variable will give a BOOL value that will be used to display a dot under the day. */

  - (NSArray*) calendarMonthView:(TKCalendarMonthView*)monthView marksFromDate:(NSDate*)startDate toDate:(NSDate*)lastDate;
Mrunal
  • 13,982
  • 6
  • 52
  • 96