如何将MaxDate和MinDate设置为从ios上的webservice返回的DatePicker [英] how to set MaxDate and MinDate to DatePicker returned from webservice on ios
问题描述
我有一个XML响应,它返回以下数据作为回复
I have a an XML response which returns the below data as response
Start Day of the Week-Wednesday
End Day of the Week-Sunday
Start time -16:00
End time -19:00
现在我知道如何解析这些值,但是我对如何将这些值设置为日期选择器的MaxDate和MinDate感到困惑,因为返回的响应总是不一样,可能会在以后更改,我的意思是后来的一周开始,一周的结束日可能会改变,所以如何实现它以便它会有效...请帮助我的朋友..我尝试了一些代码,但我不确定我是否在正确的道路上,所以请告诉我方向并帮助我
Now I know how to parse these values ,but I am getting confused on how can I set these values to MaxDate and MinDate of the Date Picker,because the returned response is not same always and may change later,I mean later start day of the week ,end day of the week may change,so how shall I implement it so that it will be efficient..please help me friends..I tried some code which is below,but I am not sure whether i am on the right path,so please show me direction and help me out
NSDate *today = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
[Gregorian setfirstDayofWeek:2];
NSDateComponents * comps =[[NSDateComponents alloc]init];
[comps setday:7];
推荐答案
所以我建议你创建两个 UIDatePicker
或一个自定义 UIDatePicker
。
So I suggest you to create two UIDatePicker
's or one custom UIDatePicker
.
如果您先选择方法,您可以按以下方式在 UIDatePicker
中设置时间范围:
If you will select first approach, you can set ranges of time in UIDatePicker
in following way:
使用IB:
- 选择
日期选择器
。 - 打开
实用程序 - >属性检查器
- 块
约束
: - 选择
最短日期
并设置其值01/01/1970 16:00:00
- 选择
最大日期
并设置其值01/01/1970 19:00:00
- 设定值
日期
至01/01/1970 16:00:00
- Select your
Date picker
. - Open
Utilities -> Attribute inspector
- In block
Constraints
: - Select
Minimum Date
and set its value01/01/1970 16:00:00
- Select
Maximum Date
and set its value01/01/1970 19:00:00
- Set value
Date
to01/01/1970 16:00:00
这篇关于如何将MaxDate和MinDate设置为从ios上的webservice返回的DatePicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!