簡體   English   中英

如何將Tapku Calendar Framework與NSFetchRequest一起使用?

[英]How to use Tapku Calendar Framework with NSFetchRequest?

我正在嘗試使Tapku日歷庫在我的應用程序中使用核心數據。 我已經設置了日歷,但現在要做的是讓點標記顯示要保存在核心數據中的日期。

我正在嘗試遵循此示例(http://developinginthedark.com/posts/iphone-tapku-calendar-markers ),但是將其與核心數據混合時會遇到麻煩。

我需要使用的方法是:

- (NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate {    
    NSLog(@"calendarMonthView marksFromDate toDate");   
    NSLog(@"Make sure to update 'data' variable to pull from CoreData, website, User Defaults, or some other source.");
    // When testing initially you will have to update the dates in this array so they are visible at the
    // time frame you are testing the code.
    NSArray *data = [NSArray arrayWithObjects:
                     @"2011-01-01 00:00:00 +0000", @"2011-12-01 00:00:00 +0000", nil]; 


    // Initialise empty marks array, this will be populated with TRUE/FALSE in order for each day a marker should be placed on.
    NSMutableArray *marks = [NSMutableArray array];

    // Initialise calendar to current type and set the timezone to never have daylight saving
    NSCalendar *cal = [NSCalendar currentCalendar];
    [cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];

    // Construct DateComponents based on startDate so the iterating date can be created.
    // Its massively important to do this assigning via the NSCalendar and NSDateComponents because of daylight saving has been removed 
    // with the timezone that was set above. If you just used "startDate" directly (ie, NSDate *date = startDate;) as the first 
    // iterating date then times would go up and down based on daylight savings.
    NSDateComponents *comp = [cal components:(NSMonthCalendarUnit | NSMinuteCalendarUnit | NSYearCalendarUnit | 
                                                    NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSSecondCalendarUnit) 
                                          fromDate:startDate];
    NSDate *d = [cal dateFromComponents:comp];

    // Init offset components to increment days in the loop by one each time
    NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
    [offsetComponents setDay:1];    


    // for each date between start date and end date check if they exist in the data array
    while (YES) {
        // Is the date beyond the last date? If so, exit the loop.
        // NSOrderedDescending = the left value is greater than the right
        if ([d compare:lastDate] == NSOrderedDescending) {
            break;
        }

        // If the date is in the data array, add it to the marks array, else don't
        if ([data containsObject:[d description]]) {
            [marks addObject:[NSNumber numberWithBool:YES]];
        } else {
            [marks addObject:[NSNumber numberWithBool:NO]];
        }

        // Increment day using offset components (ie, 1 day in this instance)
        d = [cal dateByAddingComponents:offsetComponents toDate:d options:0];
    }

    [offsetComponents release];

    return [NSArray arrayWithArray:marks];
}

有一個類似TKCalendarMonthView的類,該類將根據要從核心數據給出的數組來顯示點。 如果兩個日期都匹配,那么來自核心數據的數組(將是一個日期)將與日歷中顯示的特定月份的日期進行比較,然后BOOL將返回,因為它將標有“。”。

您可以使用以下方法進行操作:

     - (void) generateDataForStartDate:(NSDate*)start endDate:(NSDate*)end
        {

                 //just check the condition according to you...It;s your logic that would work
                 if([datestring isEqualToString:strtemp])
                    {
                        Done=YES;
                        [dataDictionary setObject:str forKey:d];//USed to show the data
                        [dataArray addObject:[NSNumber numberWithBool:YES]]; // This array would store the place where you need to set the Dot in Calender
                        j=1;
                    }
        // This is the logic for not setting the DOT
         if(j==0){
            [dataArray addObject:[NSNumber numberWithBool:NO]];
                }

        TKDateInformation info = [d dateInformation];
        info.day++;
        Done=NO;
        d = [NSDate dateFromDateInformation:info];
        if([d compare:end]==NSOrderedDescending) break;


        }

希望可以解決您的問題。...否則,您可以自己設置[dataArray addObject:[NSNumber numberWithBool:NO]]; 根據您的情況選擇是/否。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM