【发布时间】:2015-11-13 10:11:31
【问题描述】:
我有一个包含多个单元格的 UITableView。每个单元格都有一个 标签和 UITextField。当我加载 ViewController 时,UITextFields 具有初始值,用户可以编辑这些值。现在我想添加一个保存按钮来保存更改,但是在编辑后获取 UITextFields 中的值时遇到问题。我想我需要为文本字段使用标签,但我不知道如何。这是我的代码:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:EditProfileCell = tableView.dequeueReusableCellWithIdentifier("profile") as! EditProfileCell
if (indexPath.row == 1){
cell.setRow("label", value: "initial value")
cell.itemValue.tag = indexPath.row
}
@IBAction func saveTapped(sender: UIButton) {
print(self.tableView(profileTableView, cellForRowAtIndexPath: NSIndexPath(forRow: 1, inSection: 1)).viewWithTag(1))
}
当点击保存按钮时,它会打印初始值而不是编辑后的值。我需要帮助才能在编辑后获取值。
EDIT1:
我发现我可以在 didSelectRowAtIndexPath 函数中获取编辑后的值。但问题是当我点击文本字段(文本字段进入编辑模式)时,在我点击单元格内但文本字段外的空间之前不会调用 didSelectRowAtIndexPath。所以我的问题变成了当我只点击文本字段时如何触发 didSelectRowAtIndexPath。
【问题讨论】:
-
对类和 is-a 与 has-a 的理解应该对您有很大帮助。
标签: ios swift uitableview