首页 > 解决方案 > 通过 UITextFields 约束问题交换

问题描述

我有一个带有表格视图和文本字段的 EditProfileViewController。在其中一个文本字段中,我有一个作为 inputView 的 pickerView 和一个在 inputAccessoryView 中的工具栏。当视图加载并且我选择 firstName 文本字段,然后返回并移动到 lastName 文本字段时,我会收到一个约束警告。

[LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. 
Try this: 
    (1) look at each constraint and try to figure out which you don't expect; 
    (2) find the code that added the unwanted constraint or constraints and fix it. 
(
"<NSLayoutConstraint:0x2809a4640 'assistantHeight' TUISystemInputAssistantView:0x1113b11a0.height == 45   (active)>",
"<NSLayoutConstraint:0x2809a0320 'assistantView.bottom' TUISystemInputAssistantView:0x1113b11a0.bottom == _UIKBCompatInputView:0x11a437e80.top   (active)>",
"<NSLayoutConstraint:0x2809a05a0 'assistantView.top' V:|-(0)-[TUISystemInputAssistantView:0x1113b11a0]   (active, names: '|':UIInputSetHostView:0x11d06ce50 )>",
"<NSLayoutConstraint:0x280943840 'inputView.top' V:|-(0)-[_UIKBCompatInputView:0x11a437e80]   (active, names: '|':UIInputSetHostView:0x11d06ce50 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x2809a0320 'assistantView.bottom' TUISystemInputAssistantView:0x1113b11a0.bottom == _UIKBCompatInputView:0x11a437e80.top   (active)>

当我在两个默认文本字段之间切换时,会发生这种情况,我不明白为什么。我做了一些研究,据我所知,这是 iOS 13 的一个错误,因为在另一台装有 iOS 10 的设备上,这并没有发生。

消除此约束问题的解决方法是设置 autoCorrectionType = false。但我想启用它。我认为发生这种情况是因为我在 countryTextfield 的 inputView 中有一个 pickerView,但我不知道如何解决这个问题。

标签: iosuitextfieldswift4uipickerview

解决方案


这开始在我的 iOS13 应用程序中发生,我怀疑这是一个错误。在尝试了我能想到的一切之后,我关闭了自动更正并停止遇到约束问题。

textEdit.autocorrectionType = .no

推荐阅读