Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get selected row of UIDatePicker while spinning

I have a UIDatePicker in a view whose controller is in a UINavigationController. I'm registering changes in the selected date like this:

[self.datePicker addTarget:self.alarm action:@selector(timeChanged:) forControlEvents:UIControlEventValueChanged];

It works well, except if the user presses the back button in the UINavigationController before the date picker has completely settled. In that case, the timeChanged: method isn't being called, and so I'm not getting the new date.

Nothing is being released when I press the back button, it's just that the view controller is being popped off. (A reference to it is maintained).

I've found solutions to this problem with UIPickerView that involve implementing delegate methods for the picker view (eg: UIPickerView: Get row value while spinning?). But unless I'm very mistaken, that's not an option with a UIDatePicker. If possible, I'd like to stick with the UIDatePicker rather than a custom UIPickerView. Is there a way to do this? It doesn't have to get the selected row perfectly (within a row or two is fine), but the closer the better.

EDIT: This is for a jailbreak app, so private APIs are fine, if I can figure out what they are.

like image 211
drewmm Avatar asked Jan 24 '26 03:01

drewmm


1 Answers

As for the current APIs, there's no way of detecting whether a UIDatePicker is spinning.

This is because UIDatePicker is not a subclass of UIPickerView and it manages a UIPickerView internally.

I'm afraid the best solution here is to use a custom UIPickerView.

like image 131
Gabriele Petronella Avatar answered Jan 26 '26 16:01

Gabriele Petronella