Disable Past Date in UIDatePicker in IPhone Objective C

左心房为你撑大大i 提交于 2019-12-09 07:25:32

问题


I am new to Objective C and IPhone development.

I am using a UIDatePicker in my IPhone Application and my requirement is to allow the user to choose the future date only from the DatePicker.

To do this i want to disable past date & time in DatePicker only instead of putting a compare validation in the code.

Is this possible or there is an option to disable the past date in the DatePicker control itself.


回答1:


Did you try this

[picker setMinimumDate: [NSDate date]];



回答2:


Use the following line,to disable the previous dates of an UIDatePicker.

[picker setMinimumDate: [NSDate date]];

The current date is displayed as shown below




回答3:


For Swift :

let todaysDate = Date()

datePicker.minimumDate = todaysDate

It will not let the user to pick a date older than Today

OR

Or, if you want to reduce the code, use following way:

datePicker.minimumDate = Date()


来源:https://stackoverflow.com/questions/5296276/disable-past-date-in-uidatepicker-in-iphone-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!