CurrentCalendar怪异行为(iOS)

时间:2014-12-11 06:49:07

标签: ios iphone nsdate nscalendar

我一直在研究一个应用程序,其中有对象列表的NSDate基过滤。

当我在模拟器上测试该功能时,它运行良好。 但是当我使用真正的设备iPhone 6时,它会产生1天的差距,因此它不会过滤最后一项。

方案

iPhone 6刺激器

过滤器的工作

 array : date1 , date2 ,date 3

iPhone 6设备

 array: date1, date 2

 date 3 is not filtering but when i add one day the stimutor start from date 2 and miss date 1 and so it's working for iPhone 6

代码

 MyDates *dater= (MyDates *)allDates[index];
for(MyObject *sed in myobjectList){

    NSUInteger componentFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
    NSDateComponents *components = [[NSCalendar currentCalendar] components:componentFlags fromDate:[sed eventDate]];
    NSInteger year = [components year];

    NSInteger month = [components month];
    NSInteger day = [components day];
    NSDateComponents *components1 = [[NSCalendar currentCalendar] components:componentFlags fromDate:dater.date];
    NSInteger year1 = [components1 year];
    NSInteger month1 = [components1 month];
    NSInteger day1 = [components1 day];
    if(year==year1){
        if(month==month1){
            /* NOTE:Problem is here it works fine for iPhone 6 device and if you remove +1 check then it works fine for iPhone 6 stimulator means if(day==day1)*/
            if(day+1==day1){

                [tempList addObject:sed];
            }

        }
    }

}

告诉我发生了什么,并为我提供解决方案。 提前致谢。

0 个答案:

没有答案