iOS:如何使用谓词NSexpression检查用户输入的有效性和一致性 [英] iOS: How to use predicates NSexpression to check user input for validity and conformance

查看:511
本文介绍了iOS:如何使用谓词NSexpression检查用户输入的有效性和一致性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序使用coredata我有一个实体有两个属性 GridValue (数值), RecordingDate (NSdate))。一个表格视图中的用户每天可以输入这两个值,并且使用提取控制器记录它们。为了更好地了解这里的两个视图的屏幕截图:





Addviewcontroller 是用户在其中添加新值并且当用户点击静态表格视图中的两个字段中的任何一个时,他会被重定向到Zahl Datum视图进行编辑。



我想做的是检查用户输入的 GridValue ,并显示一个警告(可能是一个警告消息,或在这种情况下,将显示或弹出新的输入值(前一个存储的RecordingDate值(来自CoreData模型的NSdate输入属性))。



示例说明,如果当前用户输入:Zahlerstand = 1254 和基准: 12,05,2013 ,在上一条记录中的值为:Zahlerstand = 1300 和基准: 11.05.2013。,我们看到在连续日期新值小于旧值。在这种情况下,应在 addviewcontroller 中点击保存按钮之前,显示警告(如表格部分页脚中所示)。

$ b $



提前感谢,

解决方案

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

  compare:method返回一个NSComparisonResult值,表示接收者和另一个给定日期的时间顺序。

- (NSComparisonResult)compare:(NSDate *)anotherDate

switch([olderDate compare: newDate]){
case NSOrderedAscending:
// olderDate早于newDate
break;
case NSOrderedSame:
//两个日期相同
break;
case NSOrderedDescending:
// oldDate比newDate更晚
break;
}


In my app using coredata i have an entity with two attributes GridValue(numerical value), RecordingDate(NSdate)). The user in one tableview can enter these two values each day and they are recorded with a fetch controller. For more understanding here is a screenshot of the two views concerned with the issue:

Th Addviewcontroller is where the user adds a new value and when user clicks on any of the two fields in the static tableview, he is redirected to the "Zahl Datum" view for editing.

What I would like to do is to check the GridValue entered by the user and display a warning(could be an alert message or in this case the footer message that would show or pop up whenever the new entered value is less than a previous value entered in a different day(a previous stored value of RecordingDate(the NSdate input attribute from CoreData model).

Example to illustrate if the current user enters: Zahlerstand = 1254 and Datum: 12,05,2013, and in a previous record the values were: Zahlerstand = 1300 and Datum: 11.05.2013. then we see than new value is smaller than old value on successive dates. In this case a warning should be displayed(as in the tableview section footer. before he can click on "save" button in the addviewcontroller.

Please help with some sample code if possible.

Thank you in advance,

解决方案

Use NSComparisonResult for comparing older date to newer date as :

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

这篇关于iOS:如何使用谓词NSexpression检查用户输入的有效性和一致性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆