I have a UIPickerView and I would like to be notified when the selectRow animation is done.
I tried the following approach in my view controller which has a reference to the UIPickerView and it won't work:
-(void)viewDidLoad
{
...
[UIPickerView setAnimationDelegate:self];
[UIPickerView setAnimationDidStopSelector:@selector(animationFin ished:finished:context];
...
}
- (void)animationFinishedNSString *)animationID finishedBOOL)finished contextvoid *)context
{
if (finished) {
}
}
Then somewhere in my code, I initiate the animation:
[picker selectRow:random() % pickerDataCount inComponent:0 animated:YES];
you need to nest the method call into a beginAnimations/commitAnimation block.
you could post a notification to self from viewForRow when it asks view for component & row you are interested.
You just need to hold row & component as properties and set them before you call selectRow. And, in viewForRow
if ( (component == [self component] && (row == [self row] ) post a notification to self
I solved it with a mix out of different Answers mentioned here. The behaviour will be that it will wait until the scrolling finished and then save the selected value.
Create two variables, which store the scrolling state and the should save state. In the didSet you will check, if the the save button has been pressed while the picker is scrolling. If yes, call save after the picker has finished scrolling.
To recognize if the picker is scrolling, add
pickerViewIsScrolling = true
in theviewForRow
method of the picker.To recognize if the picker has stopped scrolling add
pickerViewIsScrolling = false
to thedidSelectRow
of the picker.In your
save()
function add the following to check wether the picker is scrolling (and save after it stopped) or is not scrolling and save directly.And finally add to your
viewDidAppear
function this line to catch thepickerViewIsScrolling = true
of the initial generated views.This works fine for me. I also implemented the deactivation of the button while save was pressed and it is waiting for the scrolling to finish. So the user won't be confused why nothing is happening until the scrolling stops.