美文网首页
FSCalendar的bug

FSCalendar的bug

作者: YannChee | 来源:发表于2017-12-12 17:18 被阅读22次

正确代码:

- (void)awakeFromNib {
    [super awakeFromNib];
    //
    [self setupCalendar];
    //
    self.chinaCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];

// 上一月
- (void)previousClicked:(id)sender
{
    NSDate *currentMonth = self.calendar.currentPage;
//    NSCalendar *chineseCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
    
    NSDate *previousMonth = [self.chinaCalendar dateByAddingUnit:NSCalendarUnitMonth value:-1 toDate:currentMonth options:0];
    [self.calendar setCurrentPage:previousMonth animated:NO];
    
//    QYLog(@"===%@",self.calendar.currentPage);
    NSDateComponents *comp = [NSDate dateComponetsWithDate:previousMonth];
    NSString* yearStr = [NSString stringWithFormat:@"%zd",comp.year];
    NSString* monthStr = [NSString stringWithFormat:@"%zd",comp.month];
    if (self.calendarChangeBlock) {
        self.calendarChangeBlock(yearStr, monthStr);
    }
}

 // 下一月
- (void)nextClicked:(id)sender
{
    NSDate *currentMonthDate = self.calendar.currentPage;
    //
//    NSCalendar *chineseCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
    //
    NSDate *nextMonthDate = [self.chinaCalendar dateByAddingUnit:NSCalendarUnitMonth value:1 toDate:currentMonthDate options:0];
    //
    [self.calendar setCurrentPage:nextMonthDate animated:NO];
    NSDateComponents *comp = [NSDate dateComponetsWithDate:nextMonthDate];
    //        NSLog(@"-----%d",comp.month);
    NSString* yearStr = [NSString stringWithFormat:@"%zd",comp.year];
    NSString* monthStr = [NSString stringWithFormat:@"%zd",comp.month];
    if (self.calendarChangeBlock) {
        self.calendarChangeBlock(yearStr, monthStr);
    }
}



}

下面是错误代码:

// 上一月
- (void)previousClicked:(id)sender
{
    NSDate *currentMonth = self.calendar.currentPage;
    NSCalendar *chineseCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
    NSDate *previousMonth = [chineseCalendar dateByAddingUnit:NSCalendarUnitMonth value:-1 toDate:currentMonth options:0];
    [self.calendar setCurrentPage:previousMonth animated:NO];
    
//    QYLog(@"===%@",self.calendar.currentPage);
    NSDateComponents *comp = [NSDate dateComponetsWithDate:previousMonth];
    //        NSLog(@"-----%d",comp.month);
    NSString* yearStr = [NSString stringWithFormat:@"%zd",comp.year];
    NSString* monthStr = [NSString stringWithFormat:@"%zd",comp.month];
    if (self.calendarChangeBlock) {
        self.calendarChangeBlock(yearStr, monthStr);
    }

//


}

 // 下一月
- (void)nextClicked:(id)sender
{
    NSDate *currentMonthDate = self.calendar.currentPage;
    //
    NSCalendar *chineseCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierChinese];
    //
    NSDate *nextMonthDate = [chineseCalendar dateByAddingUnit:NSCalendarUnitMonth value:2 toDate:currentMonthDate options:0];
    //
    [self.calendar setCurrentPage:nextMonthDate animated:NO];
    NSDateComponents *comp = [NSDate dateComponetsWithDate:nextMonthDate];
    //        NSLog(@"-----%d",comp.month);
    NSString* yearStr = [NSString stringWithFormat:@"%zd",comp.year];
    NSString* monthStr = [NSString stringWithFormat:@"%zd",comp.month];
    if (self.calendarChangeBlock) {
        self.calendarChangeBlock(yearStr, monthStr);
    }

相关文章

网友评论

      本文标题:FSCalendar的bug

      本文链接:https://www.haomeiwen.com/subject/cgunixtx.html