开发者

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:pickerViewTypesC开发者_如何学JAVAarburants];
        [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 :)


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(...)];


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


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 :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜