UITextfield issue with UIPicker view

假装没事ソ 提交于 2019-12-11 01:44:29

问题


Here is image of view I have following problem. I created a sample user information form for user. He fills some details and submits. See the first sub image in above screenshot.

I am entering first name and last name here, normal keyboard will appear when I switch first name to last name manually by scrolling a view or by using keyboard next button on keyboard.

Then, when click code textfield, a uipickerview/UIActionsheet will appear. Plase see previous image.

It is working fine. When I move one firstname textfield to last name text field and from lastname to code text field.

Problem : My problem is that, suppose currently I am lastname textfield i.e I am entering my last name and I clicked on code textfield following issue is coming. seen the below image.Here is my problem

So here, keyboard is appearing as well as uipickerview/UIactionsheet is also coming but in behing keyboard. I don't know it is coming. Not only last name to code textfield form first name tp code textfield or email textfield to code textfield...same issue is coming only when I move to one textfield to next field by scrolling/switching. If I use next button from keyboard it is moving and working file.

Anybody help me to sort out this problem.

Here my code,

@interface CreateTicketViewController ()

- (void)countryCodeWasSelected:(NSNumber *)selectedIndex element:(id)element;

@end

@implementation CreateTicketViewController


- (IBAction)countryCodeClicked:(id)sender {
    [self removeKeyboard];

    [ActionSheetStringPicker showPickerWithTitle:NSLocalizedString(@"Select CountryCode",nil) rows:_countryArray initialSelection:0 target:self successAction:@selector(countryCodeWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:sender];
}


- (void)actionPickerCancelled:(id)sender {
    NSLog(@"Delegate has been informed that ActionSheetPicker was cancelled");
}


- (void)countryCodeWasSelected:(NSNumber *)selectedIndex element:(id)element{
    // self.selectedIndex = [selectedIndex intValue];

    //may have originated from textField or barButtonItem, use an IBOutlet instead of element
    self.codeTextField.text = (_codeArray)[(NSUInteger) [selectedIndex intValue]];
}



#pragma mark - UITextFieldDelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField {
if (textField==_codeTextField) {
        [_codeTextField resignFirstResponder];
         _codeTextField.tintColor = [UIColor clearColor];
        [self removeKeyboard];

        [ActionSheetStringPicker showPickerWithTitle:NSLocalizedString(@"Select CountryCode",nil) rows:_countryArray initialSelection:0 target:self successAction:@selector(countryCodeWasSelected:element:) cancelAction:@selector(actionPickerCancelled:) origin:self.view];
         //return NO;
    }

Here is method for removeKeyboard.

UIToolbar *toolBar= [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
    UIBarButtonItem *removeBtn=[[UIBarButtonItem alloc]initWithTitle:@"Done" style:UIBarButtonItemStylePlain  target:self action:@selector(removeKeyBoard)];


-(void)removeKeyboard{
    [_emailTextField resignFirstResponder];
   // [_mobileTextField resignFirstResponder];
  //  [_msgTextField resignFirstResponder];
    [_subjectTextField resignFirstResponder];
    [_firstNameTextField resignFirstResponder];


}

回答1:


again same question, check my solution..! I already posted answer for this. https://stackoverflow.com/a/46903445/8174920




回答2:


You have to do like this :

_codeTextField.inputView = YOURPICKER


来源:https://stackoverflow.com/questions/46500610/uitextfield-issue-with-uipicker-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!