Tapku图书馆标记来自Api的日期

时间:2013-09-24 21:45:42

标签: ios nsmutablearray nsarray monthcalendar tapku

我试图使用Tapku库,我需要标记我有事件的日期。

我的api结果是:

  "month":08; 
 "calendarDays": [
    "17",
    "24"
]

以下是我的代码:

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

    NSMutableArray *marks = [NSMutableArray array];


    SCCalenderElemDaysConnection *connection=[[SCCalenderElemDaysConnection alloc]init];
    [connection obtieneListadoCalenderElemDays:^(SCCalenderElems *CalArr) {
        self.CalenderDays=CalArr.calenderDays;

        self.CalenderDays = [NSArray arrayWithObjects:
                             [NSString stringWithFormat:@"2013-09-%@ 22:00:00 +0000",[self.CalenderDays objectAtIndex:0]],@"2013-09-12 22:00:00 +0000", nil];


        NSDate *d = startDate;

        while(YES){

            if ([self.CalenderDays containsObject:[d description]]) {
                [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(@"Marks %@",marks); // here marks have values


    } :selectedMonth conToken:@"test" failure:^(NSError *error) {
        NSLog(@"ERROR CALENDER DAYS %@",error);
    }];


      NSLog(@"MarkArray %@",marks); //marks null value

    return [NSArray arrayWithArray:marks];
}

我的数据块是空的。我该如何解决这个问题?

提前致谢。

1 个答案:

答案 0 :(得分:0)

我解决了我的问题。我需要重装我的日历。因为我的块是异步的。

   .....


[self.monthview reloadData];   // is my solution


} :selectedMonth conToken:@"test" failure:^(NSError *error) {
    NSLog(@"ERROR CALENDER DAYS %@",error);
}];

Thankss。