1

鉴于Apple 教程中的详细视图,如何使详细视图中的单元格可编辑?不只是添加或删除单元格,而是修改单元格值中的文本(单元格中的右标签)?

4

2 回答 2

1

在您的 UI 和代码中,将 UILabel 对象更改为 UITextField,以相同的方式连接它们。他们将允许编辑这些字段中的文本。

然后,您还必须连接您的 viewController 以在用户更改它们时(通过委托设置)获取它们,并设置您的模型以接受来自您的委托实现的数据。

祝你好运。

于 2012-07-24T00:25:04.993 回答
0

有一个 pod:https ://github.com/fulldecent/FDTextFieldTableViewCell

以下是相关代码:

    self.detailTextLabel?.isHidden = true
    self.contentView.viewWithTag(3)?.removeFromSuperview()
    self.textField.tag = 3
    self.textField.translatesAutoresizingMaskIntoConstraints = false
    self.contentView.addSubview(self.textField)
    self.addConstraint(NSLayoutConstraint(item: self.textField, attribute: .leading, relatedBy: .equal, toItem: self.contentView, attribute: .leading, multiplier: 1, constant: 50))
    self.addConstraint(NSLayoutConstraint(item: self.textField, attribute: .top, relatedBy: .equal, toItem: self.contentView, attribute: .top, multiplier: 1, constant: 8))
    self.addConstraint(NSLayoutConstraint(item: self.textField, attribute: .bottom, relatedBy: .equal, toItem: self.contentView, attribute: .bottom, multiplier: 1, constant: -8))
    self.addConstraint(NSLayoutConstraint(item: self.textField, attribute: .trailing, relatedBy: .equal, toItem: self.contentView, attribute: .trailing, multiplier: 1, constant: -16))
    self.textField.textAlignment = .right
于 2016-12-01T03:17:27.393 回答