I am new to Swift. In my app, I have a date picker concept. My issue is when select date button, date picker is appearing fine suppose I select DEC 20 2015. My issue is when scroll date picker wheel very fast and press done button on my date picker tool bar date is not picking . If I open date picker I want to show previously selected date example DEC 20 2015. But it shows some other dates when I scroll faster.
var datePicker:UIdatePicker
func dateselcted()
{
var date:NSDate = NSDate()
datePicker.minimumdate = date
if cell.dateText.characters.count == 0
{
//If user not select any date I am showing current date and working fine
var dateOb:AnyObject =
datePicker.setdate(date ,animated:false)
}
else
{
// Suppose user select DEC 20 2015 storing this date in one object example below and working fine but it is fails when scroll datepicker wheel very fast then it is showing the other date how to show "DEC 20 2015 " when picker wheel scrolls fastly I want to show date what I selected
var dateOb:AnyObject = DEC 20 2015
datePicker.setdate( dateOb as nsdate ,animated:false)
}
}
A date picker only invokes it's action method when the wheels stop spinning. You don't get called continuously as the wheels spin from value to value.
It doesn't look like there is any facility to do what you want (get notified of value changes as the wheels in the date picker spin.)
Furthermore, I don't think the value of a date picker (or a regular UIPickerView) changes until it stops spinning, so it will still have it's old value if you start it spinning and click the button before it stops.
Are you waiting for the scrolling to stop before pressing your done button? That may be your issue.
This answer may have what you are looking for.
The delegate
pickerView:didSelectRow:inComponent:
is not called until the picker stops spinning. If you need to determine the selected row while spinning, you will need to write some logic to guess the state when done is pressed.
There is no way to select a date like you do and still expect the date picker picking your desired date automatically. The device does not know what we think. Normally, users won't press a button until they see that date gets selected. So, I think your concern is trivial.
You can first set datePicker.date to [NSDate date], then set datePicker.date to previously selected date. the OC code for you:
datePicker.date = [NSDate date];
datePicker.date = date;
It works for me, but I don't know why.
Related
i am select future date from the FSCalendar its highlighted future date, After i need to reload or refresh the calendar . calendar coming into current date , In current date will showing into red color and future date will highlighted into blue color.
My senario in calendar after coming into current date , the current date only shown highlighted remain will be show normal.
Storyboard
programmatically
myCalendar.appearance.todayColor = .white
myCalendar.appearance.titleTodayColor = .black
I have a UIDatePicker with a minimumDate and maximumDate set. The default UI of the date picker shows all dates, including those before the minimum and after the maximum. If the user spins to an out-of-bounds date, the picker does spin back - but this is not a great user experience. Can I make it so that the picker simply doesn't display out-of-bounds dates?
In my case, this is particularly important because my app deals with historic events. The date picker starts at the current date and allows users to spin back in time. It's faintly ridiculous in this situation to show tomorrow's date below the current date.
I have a date picker that is set to not allow users to pick future dates. It's maximum date is set for the current time on viewDidLoad.
dateDatePicker.maximumDate = NSDate()
But I've been noticing a bug. Today until midday the maximum date was yesterdays date. But now, after midday it is showing todays date.
The way I implemented it: The date picker is shown and hidden with alpha when user wants to use it. So I am setting the maximum date not every time the picker is shown but once it loads the view it is in.
So I am not sure if this is a bug?
Is it has to do with timezones?
Or has to do with the fact that I am only calling dateDatePicker.maximumDate once when they view loaded and that could have happened days ago?
Or if I should reset the maximumDate every time I show the datePicker?
Yes, you should almost certainly set the maximum date each time you show the date picker.
If you set the maximum date on a previous day and then never updated it nor closed the view controller the it wouldn't change.
Set it in viewWillAppear, not viewDidLoad.
If that doesn't work, use NSCalendar and NSDateComponents to build an NSDate which is 23:59 on the current date (fetch the MM/DD/YYYY from the current date as date components, then manually set the time to 23:59. That should work.
I want to display dates in UIImagePicker within a range, I have start date and I will select start date and end date should automatically appear for a week, dates from past one week should appear. i.e if start date is 10 and end date should be displayed as 3 and dates should be Populated between 10 to 3 which should be displayed in iOS.
just use the maximumDate and minimumDate properties of UIDatePicker
I have a Date Picker on my story board but I don't want it to default to today's date. I want the date to start at July 15 1998. In the attribute inspector i set the date to that and it shows it on my story board but when I launch the application it is still on today's date. Is there something else I have to do for it to work?
[yourDatePicker setDate:[NSDate dateWithTimeIntervalSince1970:900478800]];
or if you want to be fancy:
[yourDatePicker setDate:[NSDate dateWithTimeIntervalSince1970:900478800] animated:YES];
you can put this in your viewDidLoad: