views:

368

answers:

1

I Have an a touchesEnded event that checks for when a UITextField is pressed. What I would like it to do is is hide/show a UIPickerView. How can this be done?

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([self.textField frame], [touch locationInView:self.view]))
{
    NSString * error = @"Touched the TextField";
    UIAlertView * errorAlert = [[UIAlertView alloc] initWithTitle:@"Selection!" message:error delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
    //Want to show or hide UIPickerView
}

}

I already have an allocated UIPickerView when touches occur

@interface ThirdViewController : UIViewController <UITextFieldDelegate,UIPickerViewDelegate> {


IBOutlet UIPickerView *pickerView;

}

+1  A: 

UIPickerView inherits from UIView, so you should be able to just toggle its 'hidden' property:

if (pickerView) pickerView.hidden = !pickerView.hidden;
Joe Strout