【问题标题】:Can't hide Done bar over keyboard无法在键盘上隐藏完成栏
【发布时间】:2018-04-12 11:31:06
【问题描述】:

我为文本字段分配了一个数字键盘。我不想在键盘上方或键盘内部显示任何已完成的按钮栏,但我无法隐藏该栏。

我正在尝试删除此栏:

我尝试做的是:

- (void)viewDidLoad {
    [super viewDidLoad];
    _txtAge.delegate=self;
    [_txtAge becomeFirstResponder];
    _txtAge.autocorrectionType = UITextAutocorrectionTypeNo;
}

- (void)textFieldDidBeginEditing:(UITextField*)textField
{
    UITextInputAssistantItem* item = [textField inputAssistantItem];
    item.leadingBarButtonGroups = @[];
    item.trailingBarButtonGroups = @[];
}

XCode 版本:9.3 (9E145)

【问题讨论】:

标签: ios objective-c xcode uitextfield


【解决方案1】:

试试这个:

_txtAge.inputAccessoryView = nil;

完整代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    _txtAge.delegate=self;
    _txtAge.inputAccessoryView = nil;
    [_txtAge becomeFirstResponder];
    _txtAge.autocorrectionType = UITextAutocorrectionTypeNo;
}

// or try this

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

  if (textField == _txtAge) {
    _txtAge.inputAccessoryView = nil;
  } 

  return true;
}

// or try this

- (void)textFieldDidBeginEditing:(UITextField *)textField {
  if (textField == _txtAge) {
    _txtAge.inputAccessoryView = nil;
  } 
}

【讨论】:

  • 不幸的是,这三种方法都没有帮助。我没有在我的代码中设置任何附件。只是在情节提要中为相关文本字段选择了数字键盘。
  • 尝试在你的源代码中找到这个关键字inputAccessoryView。没有 textfield 的 inputAccessoryView,它不能显示这个工具栏。或者尝试检查影响此的任何其他扩展或外部库
  • 我没有任何“inputAccessoryView”代码,除了_txtAge.inputAccessoryView = nil;
【解决方案2】:
- (void)textFieldDidBeginEditing:(UITextField*)textField{
   if (textField != self.yourTextField){
      UITextInputAssistantItem* item = [textField inputAssistantItem];
      item.leadingBarButtonGroups = @[];
      item.trailingBarButtonGroups = @[];
   }else{
      textField.inputAccessoryView = nil;
   }
}

【讨论】:

  • 只放:self.yourTextField.inputAccessoryview = nil;在你的 viewDidLoad 中。
  • 没有帮助。它没有消失。
猜你喜欢
  • 2020-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-17
  • 1970-01-01
  • 2013-11-04
相关资源
最近更新 更多