xcode - 如何在TapKu库中选择多个日期?

标签 xcode tapku

我想显示tapkilibrary中的多个选定日期。例如突出显示2011年8月14日至2011年8月18日之间的日期 .

最佳答案

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

NSLog(@"Date Selected is %@",date);
        //txtbdate.text=date;

    NSDateFormatter *timeFormat = [[[NSDateFormatter alloc] init] autorelease];
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [timeFormat setDateFormat:@"yyyy-MM-dd"];
    [timeFormat setTimeZone:gmt];


    //[timeFormat setLocale:[NSLocale currentLocale]];
    //[timeFormat setTimeZone:[NSTimeZone localTimeZone]]; 
    NSString *theTime = [timeFormat stringFromDate:date];   
    NSLog(@"%@",theTime); 
    objappdel.strdate=theTime;

    [tkmonthView reload];
    AppointmentDetail *appointmentDetail=[[AppointmentDetail alloc]initWithNibName:@"AppointmentDetail" bundle:nil];
    [self.navigationController pushViewController:appointmentDetail animated:YES];
    [appointmentDetail release];
}

- (NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate
{   
    NSMutableArray * data = [[NSMutableArray alloc] init];
    NSDateFormatter *dateForm = [[NSDateFormatter alloc] init];
    NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
    [dateForm setDateFormat:@"yyyy-MM-dd"];
    [dateForm setTimeZone:gmt];
    NSDate *date ;


    for (int i=0; i<[objappdel.arrDate count]; i++)
    {
        NSString *time;
        time=[objappdel.arrDate objectAtIndex:i];
        //time=  [[[jobData valueForKey:@"Record"] objectAtIndex:i] valueForKey:@"JobStartDate"];
        //time = [[time componentsSeparatedByString:@" "] objectAtIndex:0];
        date = [dateForm dateFromString:time];
        [data addObject:[NSString stringWithFormat:@"%@",date]];
    }
    NSArray *copy = [data copy];
        NSInteger index = [copy count] - 1;
        for (id object in [copy reverseObjectEnumerator]) 
        {
            if ([data indexOfObject:object inRange:NSMakeRange(0, index)] != NSNotFound) 
            {
                [data removeObjectAtIndex:index];
            }
            index--;
        }

    NSLog(@"sorted dates are %@",copy);
    // 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:(NSYearCalendarUnit | NSMonthCalendarUnit |
                                              NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | 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
        //NSLog(@"%@",[d description]);

        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];
}

使用此委托(delegate)方法。它将返回您想要突出显示的日期的 NSArray。

关于xcode - 如何在TapKu库中选择多个日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7282746/

相关文章:

iphone - 使用 Tapku Calendar 创建透明日历

iphone - 如何将数据从 web 服务填充到 UIPickerView? [iOS应用程序开发]

Xcode 4 无法识别框架 header 目录已提交 (GIT)

iphone - 如何使用一个 View 打开图像文件?

ios - 将 tapku 日历添加到 ios 应用程序

iphone - 如何更改Tapku日历的背景图像

ios - 如何根据 TAPKU 日历中的日期检查 NSDate

ios - Tapku日历的日期格式

xcode - 解析 AppleScriptObjC 中的 NSAppleEventDescriptor

xcode - NSTableView - 预高亮某一行