views:

615

answers:

2

Does anyone have a basic example to display a UIPickerView when a UITextField was selected.

A: 

The best place to do so would be in the NSTextField Delegate method:

- (BOOL)textShouldBeginEditing:(NSText *)textObject

Override the method to return NO and instead evoke the picker view. Returning NO will prevent the keyboard from appearing.

TechZen
A: 

What I did was implement touchesEnded event. If that event occurs in my UITextField parameters then I either hide or show the UIPickerView

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{    
    UITouch *touch = [[event allTouches] anyObject];

    if (CGRectContainsPoint([self.textField frame], [touch locationInView:self.view]))
    {
        //Want to show or hide UIPickerView
        if(pickerView)
        {
            submitButton.hidden = !submitButton.hidden;
            pickerView.hidden = !pickerView.hidden;
        }
    }
}
aahrens