ios - 用户点击按钮时如何清除输入的文本字段?
问题描述
我正在处理注册表单,当用户点击按钮时填写多个文本字段后,文本字段应该是清晰的。
解决方案
如果你不想使用 UITextField 集合,你可以使用这个,
@IBAction func buttontapped(_ sender: Any) {
self.view.subviews.forEach({ item in
if item.isKind(of: UITextField.self) {
let txtItem = item as! UITextField
txtItem.text = ""
}
})
}
按照@vacawama 的建议更新,
@IBAction func buttontapped(_ sender: Any) {
for case let txtItem as UITextField in self.view.subviews {
txtItem.text = ""
}
}
假设:所有文本字段都是self.view
直接的子视图。如果 textfields 是 other 的子视图,则customview
应该使用它customview
而不是self.view
推荐阅读
- c# - DocuSign JWT Auth Error while requesting server, received a nonsuccessful HTTP code Error with response Body C# sdk
- laravel - 将标头中的刷新令牌发送到 Laravel 后端
- html - 我想取消阻止我的客户网站和我的生产网站从我自己的网站加载资产
- java - 如何在 Spring Boot API 请求中强制执行 DateTime 格式?
- ios - 是否可以从 macOS 应用程序编辑 iOS 文件?
- react-native - 使图像适合视图反应原生
- javascript - 我正在使用 axios 在 React 中制作一个 CRUD Web 应用程序。我收到以下错误:“TypeError: Object(...) is not a function”
- python - 如何使用 selenium 使 chrome 浏览器在后台运行
- python - cv2 断言失败错误,p.checkVector(2, CV_32S) 问题与 FillPoly
- sql - 查询 SQL AND 运算符