ios - 从 TextField 读取输入
问题描述
我正在尝试从多个 TableViewCell 中读取来自 2 个文本字段的输入,看起来它只能访问 input2 并将 input2 两次附加到 inputRead 数组中。我该如何解决这个问题?非常感谢
P/S:这就是我在一个单元格中布局 2 个文本字段的方式:[input1] [input2]
override func tableView(_ tableView: UITableView, cellForRowAt
indexPath: IndexPath) -> UITableViewCell {
let customCell = tableView.dequeueReusableCell(withIdentifier: "CustomCell") as! CustomCell
customCell.input1.tag = indexPath.row
customCell.input2.tag = indexPath.row
customCell.input1.delegate = self
customCell.input2.delegate = self
return customCell
}
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
return textField.endEditing(true)
}
func textFieldDidEndEditing(_ textField: UITextField) {
let indexPath = IndexPath(row: textField.tag, section: 0)
if let customCell = self.table.cellForRow(at: indexPath) as?
CustomCell {
let string1 = String(customCell.input1.text!)
let string2 = String(customCell.input2.text!)
inputRead.append(input(string1, string2))
}
}//end class
class CustomCell : UITableViewCell{
@IBOutlet weak var input1: UITextField!
@IBOutlet weak var input2: UITextField!
}
解决方案
推荐阅读
- django - I need to append a value in an array to another value in python
- html - 如何使浮动图像居中
- .net - 使用 .NET JWT 中间件验证自定义令牌以及 Azure 令牌
- reactjs - React Link Button 不会滚动到顶部
- python - 如何根据熊猫中的不同列创建相关性?
- python - 在熊猫中按相似日期分组
- angular - 使用 Papa Parse Angular 创建 Excel CSV 模板
- r - 包含每周数据的数据透视表
- xpath - 使用 XPath 查找没有 ALT 属性的图像
- c# - 在asp.net c# web应用程序中,数据没有被插入到mysql数据库中