【发布时间】:2016-11-04 19:31:05
【问题描述】:
我试图弄清楚如何以有序的方式从表格视图中的单元格获取文本字段数据。到目前为止,我能够在每个文本字段中输入检索类型数据。要以正确的顺序执行此操作,尽管用户必须编辑第一个单元格...最后一个单元格,任何其他方式并且数据的顺序不正确。
例如:
我让程序创建 5 个带有文本字段的单元格,
- textfield1:我第二次在这里输入
- textfield2:我在这里输入了第四个
- textfield3:我先在这里输入
- textfield4:我在这里输入了第五个
- textfield5:我在这里输入了第三个
按照我目前的方式,我的 dataArray 看起来与这个相同,因为它是根据输入的时间而不是单元格的顺序来存储的。 我想输入上面的例子,但我的数据是这样的:
- textfield1:我先在这里输入
- textfield2:我第二次在这里输入
- textfield3:我在这里输入了第三个
- textfield4:我在这里输入了第四个
- textfield5:我在这里输入了第五个
这是我的文本字段编辑代码:
@IBAction func TitleEditBegin(_ sender: UITextField) {
}
@IBAction func TitleEditEnd(_ sender: UITextField) {
print(sender.tag) // Debug
titleArray.append(sender.text!)
}
我暂时知道titleArray会附加任何其他更改,但我想先解决排序问题。
谢谢!
编辑:我忘了添加如何创建单元格,代码如下:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = TitleSessionTableView.dequeueReusableCell(withIdentifier: textCellIdentifier, for: indexPath) as! TitleSessionCell
cell.SessionTitleLabel.text = "Title"
// cell.SessionTitleField.text = "Default"
cell.SessionTitleField.tag = indexPath.row
cell.SessionTitleField.delegate = self
print(indexPath.row) // Debug
return cell
}
编辑 2:添加我定义文本字段的位置。
import Foundation
import UIKit
class TitleSessionCell: UITableViewCell{
@IBOutlet weak var SessionTitleField: UITextField!
@IBOutlet weak var SessionTitleLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
}
【问题讨论】:
标签: swift tableview textfield tableviewcell