Search code examples
iphonexcodedelayuipicker

Set delay animation for UIPicker?


If I have this code below to tell the UIPicker if nothing is selected to set the feet to 1, How can I delay this action a few seconds?

// If feet values are zero.
if (([feetPicker selectedRowInComponent:0] == 0 & [feetPicker selectedRowInComponent:1] == 0)){
// Set to one foot.
[feetPicker selectRow:1
          inComponent:1
             animated:YES];


}

Solution

  • [NSTimer    scheduledTimerWithTimeInterval:2.0    target:self    selector:@selector(fireMethod)    userInfo:nil repeats:NO];
    

    The above code can be placed whenever you want to start the timer.

    -(void)fireMethod {
        // If feet values are zero.
    if (([feetPicker selectedRowInComponent:0] == 0 & [feetPicker selectedRowInComponent:1] == 0)){
    // Set to one foot.
    [feetPicker selectRow:1
              inComponent:1
                 animated:YES];
    
    
        }
    }