ios - 如果另一个 UITextField 具有特定值,则启用特定 UITextField
问题描述
我有两个UITextField
scDiseasePicker
和optionalLMS
.
我cDiseasePicker
使用 aUIPickerView
作为输入,选项有“No”、“Yes, 1VD”、“Yes, 2VD”和“Yes, 3VD”。
如果用户选择“否”,optionalLMS
则应显示为灰色/禁用用户交互。否则,他们应该被允许编辑它。
我试过添加
func textFieldDidEndEditing(_ textField: UITextField) {
if cDiseasePicker.text == "Yes, 1VD" || cDiseasePicker.text == "Yes, 2VD" || cDiseasePicker.text == "Yes, 3VD" {
optionalLMSText.isUserInteractionEnabled = true
print("true cdisease")
} else if cDiseasePicker.text == "No" {
optionalLMSText.isUserInteractionEnabled = false
print("false cdisease")
}
}
但这似乎没有任何效果,并且没有任何内容打印到控制台。这是我的班级声明,如果有影响的话:
class NewRecord: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate
抱歉,如果这是一个基本问题,我对 Swift 还是很陌生。
解决方案
当您使用 aUIPickerView
作为输入时,您应该查看您的选择器视图didSelectRow
(我猜您正在使用它来填充您的cDiseasePicker
文本字段)以根据自己的喜好配置其他文本字段。
如果我理解正确,您需要的关键信息textFieldDidEndEditing
是在文本字段不再是第一响应者时调用该方法,而不是在文本更改时调用。
推荐阅读
- reactjs - 使用 NativeBase 的 iOS 应用程序的顶部和底部黑色熨平板
- git - 为什么更改不自动转到暂存区?
- python - get_cookies() 在 Selenium 中使用 Chrome 返回带有 Whatsapp Web 的空列表
- amazon-web-services - 如何通过cloudformation在非默认vpc上创建弹性伸缩组?
- ruby-on-rails - 如何在运行 Ruby 2.7.0 时抑制 RSpec 中的警告
- python - 当按下 Flutter 中编程的按钮时,有没有办法可以运行 python 脚本?
- graphql - 如何使用 gatsby 从内容中显示媒体内容
- python - 如何从命令行使用已安装的 pip3 包?
- javascript - 在 Card 组件中居中 Avatar 组件
- python-3.x - 指定 Spark Schema 不会显示正确的显示结果