【问题标题】:NSDate. Grabbing all dates before todayNSD日期。获取今天之前的所有日期
【发布时间】:2013-08-01 10:22:43
【问题描述】:

我正在尝试使用这个calendar component,我的任务是在今天日期之前的所有日期在视觉上和技术上都禁用。用户也可以在月份之间切换,我需要禁用今天之前的所有日期,即使它是几年前的日期。还为此日历定义了disabledDateTextColordisabledDateBackgroundColor 类型,但没有日期计算方法。我正在阅读NSDate 文档,看起来我不能直接使用系统方法(我的意思是返回日期之前或之后的日期数组或类似的方法)。看起来像将今天之前的所有现有日期添加到 NSArray 并在绘制日历之前将它们标记为禁用显然是过度杀伤,不是吗?

【问题讨论】:

    标签: ios objective-c calendar nsdate


    【解决方案1】:

    在我以前的应用程序中,我使用了这种方法

    switch ([dateOne compare:dateTwo]) {
    case NSOrderedAscending:
        // dateOne is earlier in time than dateTwo
        break;
    case NSOrderedSame:
        // The dates are the same
        break;
    case NSOrderedDescending:
        // dateOne is later in time than dateTwo
        break;
    }
    

    两个日期格式化程序应该相似 阅读下面链接中的实例方法以获取更多信息

    http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDate/compare:

    【讨论】:

    • 感谢您的关注,普拉卡什!主要问题是:我是否需要使用数组,用月份的所有日期填充它,并在我需要遍历数组时标记所有日期,还是存在更通用的决定来解决这个问题?
    • 数组和for循环是要走的路:]在那个开关中,你输入数组objectAtIndex的值和今天的日期,就是这样
    猜你喜欢
    • 2020-09-28
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    • 2021-12-11
    • 2021-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多