Malloc
Malloc

Reputation: 16296

the Picker hasn't been displayed

please i have hours with this issue without founding solution and adressing to you for that :)

i have UIPickerView which has to be displayed from the bottom of the view when the user click on a UITextField (that's what my app requirement oblige me to do), so i implement this method to catch the touch event of the text field :

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

    UITouch *touch;
    touch=[touches anyObject];
    CGPoint point=[touch locationInView:self.view];
    if(CGRectContainsPoint([typeCarburantTextField frame],point))
    {
        [self pickerTypeCarburantsShow];

    }

}

and this method to prevent the keyboard from being displayed when the user click on the text field :

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

    return NO;

}

pickerTypeCarburantsShow

-(IBAction)pickerTypeCarburantsShow{

        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 240);
        pickerViewTypesCarburants.transform=transform;
        [self.view addSubview:pickerViewTypesCarburants];
        [UIView commitAnimations];

    }

all my IB connections are pretty good, however when i run and i click the UITextField the keyboard doesn't appear but i don't see the picker showed pleaaaase help, thx in advance :)

Upvotes: 0

Views: 560

Answers (3)

Malloc
Malloc

Reputation: 16296

my problem was resolved, so the problem was in the UITextField delegate method, i have implemented the wrong method :

-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];
    return YES;
}

instead, it should be this method to show the UIPickerView :

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    [textField resignFirstResponder];
    [self pickerTypeCarburantShow];
}

where pickerTypeCarburantShow is an IBAction method which is supposed to animate the whole UIPickerView view.. hope this help who is struggling in the same issue :)

Upvotes: 0

govi
govi

Reputation: 686

What you might want is probably this one..

The UITextField has this property,

inputView

The custom input view to display when the text field becomes the first responder.

@property (readwrite, retain) UIView *inputView

Discussion If the value in this property is nil, the text field displays the standard system keyboard when it becomes first responder. Assigning a custom view to this property causes that view to be presented instead.

The default value of this property is nil.

So, to display another view instead of the keyboard, all that is required is to set that view, in this case the uipickerview or its container as the inputView for the textfield...

for example, to show some pickerview instead of the keyboard, you might want to

textView.inputView = [[UIPickerView alloc] initWithFrame:CGRectMake(...)];

Upvotes: 1

Matthew Frederick
Matthew Frederick

Reputation: 22305

Does your PickerView have both its Delegate and DataSource set? It won't show up otherwise.

Upvotes: 1

Related Questions