How to Show UIPickerView when selecting UITextField

前端 未结 8 533
Happy的楠姐
Happy的楠姐 2020-12-08 03:52

Here is a screenshot of what I did till now:

\"enter

So what I am trying to do

相关标签:
8条回答
  • 2020-12-08 04:21

    it will work for you .. i have edited it .and for that you have to set delegate for textfield. and create a UIPIckrView in NIb file.

    - (BOOL) textFieldShouldBeginEditing:(UITextView *)textView
    {
        pickrView.frame = CGRectMake(0, 500, pickrView.frame.size.width,    pickrView.frame.size.height);
        [UIView beginAnimations:nil context:NULL];
        [UIView setAnimationDuration:.50];
        [UIView setAnimationDelegate:self];
        pickrView.frame = CGRectMake(0, 200, pickrView.frame.size.width, pickrView.frame.size.height);
        [self.view addSubview:pickrView];
        [UIView commitAnimations];
        return NO;
    }
    
    0 讨论(0)
  • 2020-12-08 04:21

    Well, you could rely on the UITextFieldDelegate to handle this kind of functionality.

    Inside the

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

    is where you would set the text of your current UITextField as well as initializing and showing the UIPickerView.

    Important notice:

    You might also want to conform to the UIPickerViewDelegate.

    HTH

    0 讨论(0)
提交回复
热议问题