If you want to add some delay, you can use:
[NSThread sleepForTimeInterval:0.5]
But this will block your application, so it is better to use a timer:
[picker selectRow:0 inComponent:0 animated:YES];
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(animatePickerTimer:) userInfo:picker repeats:NO];
-(void)animatePickerTimer:(NSTimer *)timer;
{
[self performSelectorOnMainThread:@selector(animatePicker:) withObject:(UIPickerView *)timer.userInfo waitUntilDone:NO];
[timer invalidate];
}
-(void)animatePicker:(UIPickerView *)picker
{
[picker selectRow:3 inComponent:0 animated:YES];
}
This should be done in the main thread, since UIKit is not thread safe
source
share