开发者

Date validations

I have two text fields. In these text fields, I am getting dates from a picker i开发者_运维百科n this format: "mm-dd-yyyy". What I want to do is validate the dates from one text field to the other, so that both text fields are not filled with the same date and also the first text field's date is always greater than the second's. Can anyone explain how to do this on iPhone?


You can use [NSDate compare:];From documentation

compare:

Returns an NSComparisonResult value that indicates the temporal ordering of the receiver and another given date.

- (NSComparisonResult)compare:(NSDate *)anotherDate

Parameters

anotherDate

The date with which to compare the receiver. This value must not be nil. If the value is nil, the behavior is undefined and may change in future versions of Mac OS X.

Return Value

If:

The receiver and anotherDate are exactly equal to each other, NSOrderedSame

The receiver is later in time than anotherDate, NSOrderedDescending

The receiver is earlier in time than anotherDate, NSOrderedAscending.


Since, from textFields, you will be getting strings, you can do stringComparison.

[textField1.text isEqualToString:textField2.text];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜