I'm getting crashes from my UIDatePicker view and I think it's because I'm not retaining the pickers selected date. Can anyone tell me if this could be correct?
I have a modal view for selecting a toDate and a fromDate range. These values are passed into the modal view and grabbed out of the view when it's dismissed.
The view has one UIDatePicker and a segmented button for switching between the to and from dates.
Every time the segmented control switches I set the pickers date to the matching to or from date. When the picker value changes I update the to or from dates accordingly. The view crashes after a couple of switches between these dates.
I'm not retaining the pickers selected date so I'm guessing when I set the value of the pickers date from the toDate to the fromDate the toDate is being released so when I switch the picker back to the toDate it's going to crash.
Also to use the selected date from the picker outside the view will the date need to be retained as the picker will be released along with the date?
Does this make sense to anyone?
If you need to grab the date value from a UIDatePicker, you indeed need to retain a copy if you'll be using it outside the scope of the function (say, over multiple AutoreleasePool cycles).
Getting the date from a UIDatePicker will retain a reference but it will be autoreleased so effectively is only valid until the autorelease pool is destroyed.
Remember to release your reference once you've finished with it.
For simply using it temporarily inside a function, you won't need to retain it as stated above.
Why don't you set a property of your viewvcontroller or other class to the date you get using:
self.date = date;
Define date to be a #property with a retain attribute. That way you should be able to use date in other places of your app, and it won't be autoreleased when you go through the runloop.
Related
I'm using Date Picker, which is set to Count Down Timer mode. By default it displays the current time. How would I set it to display a specific time on start up? Thanks in advance.
You can use date property
UIDatePicker > date
Use this property to get and set the currently selected date
Is there a way to show DatePicker empty when Date property set to null value? I need to set it empty when page is loaded because date selection is not mandatory on my application.
Maybe a hacky workaround, but you can subclass it, and override setting the date property, and when it's null, intercept the drawing code to draw itself empty (or however you want it to be displayed when date is null) and force a redraw. When date is asserted, you can just call super's draw. Definitely not the best solution, but should work in theory.
i have a functionility for show count down timer in format, but when uidatepicker in count down timer mode , it show only HH:MM.
how i can add a extra field for second in uidatepickerview.
how i can add a extra field for second in uidatepickerview.
You can't. UIDatePicker only displays hours and minutes in countdown mode. If you need to display seconds as well, you'll have to recreate it yourself using a UIPickerView.
As always, you should file an enhancement request to request this functionality.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return 2;
}
it will create section in your picker view.
I am looking for how to disable past dates in the tapku calendar.
For instance, I want to disable all dates before the current date.
Is there any reference?
Regards,
João Paulo
I don't know of any official documentation, but I assume that you should modify the array you use as your datasource for the calendar view, possibly on - (void)viewDidAppear in your implementation.
For example, let's say you have an NSArray of events, with each array object containing an NSDictionary for the date of that event. You should iterate through the array when the view loads, comparing each item to the current date, which can be found using something like:
CFGregorianDate currentDate = CFAbsoluteTimeGetGregorianDate(CFAbsoluteTimeGetCurrent(), CFTimeZoneCopySystem()); - link to this here: How do I get the current date in Cocoa (second answer)
You can either save the modifications to a new array, or just change the old array, so long as it's mutable. From there, all you need to do is pop that new array into your:
- (NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate method, and Tapku will take care of the rest!
The default UIDatePicker shows both the date and time. I need to show only the month, day, year and time like this
How can I change the date picker to this?
Well First off I suggest reading through the UIDatePicker documentation. Here are the Date Picker Modes:
Date Picker Mode
The mode of the date picker.
typedef enum {
UIDatePickerModeTime,
UIDatePickerModeDate,
UIDatePickerModeDateAndTime,
UIDatePickerModeCountDownTimer
} UIDatePickerMode;
If you cannot find what you need there. Then you can create your own by using a UIPickerView.