【发布时间】:2017-08-13 00:37:40
【问题描述】:
我有一个带有动态单元格的UITableView(在以前的视图中是用于创建这些单元格的滑块)。
每行包含两个文本字段。
首先是距离起点。
其次是描述。
我可以通过 tableView 中的单元格访问这些文本字段。 我的表视图:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "Cell"
let cell: FirstAddPointTableViewCell = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! FirstAddPointTableViewCell
cell.numberOfCell.text? = "\(indexPath.row + 1)."
cell.distance.text? = arrayTextField1[indexPath.row]
cell.description.text? = arrayTextField2[indexPath.row]
cell.distance.tag = indexPath.row
cell.description.tag = indexPath.row
cell.distance.delegate = self
cell.description.delegate = self
return cell
我的代码中有 func textFieldDidEndEditing,但我不知道如何访问 textFields - 距离和描述以将正确的值保存到我的两个数组中。
我知道这段代码只适用于一个文本字段。如果我有两个文本字段,则此代码是错误的:
func textFieldDidEndEditing(_ textField: UITextField) {
print("End editing!")
if textField.text != "" {
arrayTextField1[textField.tag] = textField.text!
arrayTextField2[textField.tag] = textField.text!
} else if textField.text == "" {
arrayTextField1[textField.tag] = textField.text!
arrayTextField2[textField.tag] = textField.text!
}
}
还有我的 FirstAddPointTableViewCell:
import UIKit
class FirstAddPointTableViewCell: UITableViewCell {
@IBOutlet weak var cislovaniPrekazek: UILabel!
@IBOutlet weak var prekazkyFormulare: UITextField!
@IBOutlet weak var poznamkyFormulare: UITextField!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
我的“想法”类似于这段代码(textFieldDidEndEditing),但我不知道该怎么做。我无法访问它们:
arrayTextField1[distance.tag] = distance.text!
arrayTextField2[description.tag] = description.text!
你能帮帮我吗?对不起我的英语。
【问题讨论】:
标签: ios swift uitableview uitextfield