如何通过双击更改textField的isEnabled属性的值?

时间:2019-04-22 10:46:34

标签: ios swift uitextfield uitapgesturerecognizer

isEnabled的{​​{1}}属性的默认值为false。 当我双击textField时,textField属性的值应为true,以便我可以在其中写入任何内容

isEnabled

@IBOutlet var textField: UITextField! { didSet { textField.delegate = self textField.isEnabled = false textField.inputAssistantItem.leadingBarButtonGroups = [] textField.inputAssistantItem.trailingBarButtonGroups = [] let tap = UITapGestureRecognizer(target: self, action: #selector(tapHandler(_:))) tap.numberOfTapsRequired = 2 textField.addGestureRecognizer(tap) } } @objc func tapHandler(_ recognizer: UITapGestureRecognizer) { switch recognizer.state { case .ended: textField.isEnabled = true default: break } } 没有响应UITapGestureRecognizer,显然textField的值仍然为假。

1 个答案:

答案 0 :(得分:-1)

谢谢!在UITableViewCell的textField中,我为父级(即UITableViewCell)提供了UITapGestureRecognizer。