Shruti kadam
Shruti kadam

Reputation: 99

UITextfield issue with UIPicker view

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];


}

Upvotes: 2

Views: 90

Answers (2)

Mallikarjun Hanagandi
Mallikarjun Hanagandi

Reputation: 510

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

Upvotes: 2

Vini App
Vini App

Reputation: 7485

You have to do like this :

_codeTextField.inputView = YOURPICKER

Upvotes: 0

Related Questions