Search code examples
iphoneobjective-ciosuipicker

UIAlert to popup after the UIPicker is closed


I have a UIPicker that triggers a UIAlert when a row is selected. I'm trying to have the alert popup after the UIPicker "done" button is pressed and the UIPicker is closed. At the moment the alert triggers when the row is selected. So, as someone scrolls through each row in the picker a UIAlert keeps popping.

thanks for any help

here's the 'done' button code:

-(IBAction)done{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
    pickerView.transform = transform;
    [UIView commitAnimations];  

}

here's a sample of the picker UIAlert code showing 'case 0' along with the alert message:

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

UIColor *newColor;
switch (row) {
    case 0:
        newColor = [UIColor yellowColor];       
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"message" delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil];
        [alert show];
        [alert release];

        myLabel.text = @"sometext";
        break;

}


Solution

  • -(IBAction)done{
    
         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"alert" message:@"message"     delegate:nil cancelButtonTitle:@"cancel" otherButtonTitles:nil];
            [alert show];
            [alert release];
    
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 480);
        pickerView.transform = transform;
        [UIView commitAnimations]; 
    }
    
    
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    
    UIColor *newColor;
    switch (row) {
        case 0:
            newColor = [UIColor yellowColor];       
    
            myLabel.text = @"sometext";
            break;
    }
    
    }