0

在我使用 coredata 的应用程序中,我有一个具有两个属性GridValue(数值)、RecordingDate(NSdate))的实体。用户可以每天在一个 tableview 中输入这两个值,并使用 fetch 控制器记录它们。为了更好地理解,这里是与该问题有关的两个视图的屏幕截图:

在此处输入图像描述

Addviewcontroller是用户添加新值的地方,当用户单击静态表格视图中的两个字段中的任何一个时,他将被重定向到Zahl Datum”视图进行编辑。

我想做的是检查用户输入的GridValue并显示警告(可能是警告消息,或者在这种情况下,当新输入的值小于输入的先前值时,将显示或弹出页脚消息在另一天(RecordingDate 的先前存储值(CoreData 模型中的 NSdate 输入属性)。

举例说明当前用户是否输入:Zahlerstand = 1254和 Datum: 12,05,2013,在之前的记录中,值是:Zahlerstand = 1300和 Datum: 11.05.2013。然后我们看到新值在连续日期小于旧值。在这种情况下,应显示警告(如在 tableview 部分页脚中。在他可以单击addviewcontroller中的“保存”按钮之前) 。

如果可能,请帮助提供一些示例代码。

先感谢您,

4

1 回答 1

0

使用 NSComparisonResult 将旧日期与新日期进行比较:

compare: method returns an NSComparisonResult value that indicates the temporal ordering of the receiver and another given date.

- (NSComparisonResult)compare:(NSDate *)anotherDate

switch ([olderDate compare:newDate]) {
case NSOrderedAscending:
    // olderDate is earlier in time than newDate
    break;
case NSOrderedSame:
    // Both dates are same
    break;
case NSOrderedDescending:
    // olderDate is later in time than newDate
    break;
}
于 2013-07-19T09:39:37.087 回答