【问题标题】:UITextfield issue with UIPicker viewUIPicker 视图的 UITextfield 问题
【发布时间】:2017-09-30 07:34:52
【问题描述】:

Here is image of view 我有以下问题。 我为用户创建了一个示例用户信息表单。他填写了一些细节并提交。请参阅上面屏幕截图中的第一个子图像。

我在这里输入名字和姓氏,当我通过滚动视图或使用键盘上的键盘下一步按钮手动将名字切换为姓氏时,将出现普通键盘。

然后,当点击代码文本框时,会出现一个uipickerview/UIActionsheet。请看上一张图片。

它工作正常。当我将一个名字文本字段移动到姓氏文本字段并从姓氏文本字段移动到代码文本字段时。

问题:我的问题是,假设当前我是姓氏文本字段,即我正在输入我的姓氏,然后单击代码文本字段,以下问题即将到来。见下图。Here is my problem

所以在这里,键盘出现了,uipickerview/UIactionsheet 也出现了,但在键盘上。我不知道它来了。 不仅姓氏编码文本字段形式名字 tp 代码文本字段或电子邮件文本字段编码文本字段......同样的问题只有当我通过滚动/切换移动到一个文本字段到下一个字段时才会出现。如果我使用键盘上的下一个按钮,它正在移动和工作文件。

谁能帮我解决这个问题。

这是我的代码,

@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;
    }

这里是 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];


}

【问题讨论】:

  • 看不到图片!!
  • 尝试将code textfield inputView 设置为您的pickerView
  • 它不应该这样表现。您能否分享代码您如何将选择器视图添加到代码 textField 以及下一个关键操作。希望@ViniApp点是你的地址。
  • 请分享一些代码。
  • 我发布了为代码文本字段编写的代码。

标签: ios objective-c iphone uitextfield uipickerview


【解决方案1】:

同样的问题,检查我的解决方案..!我已经为此发布了答案。 https://stackoverflow.com/a/46903445/8174920

【讨论】:

    【解决方案2】:

    你必须这样做:

    _codeTextField.inputView = YOURPICKER
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      相关资源
      最近更新 更多