可以在Dynamic Prototype UITableView中的静态单元格中添加标签吗? (迅速)

时间:2016-09-04 08:24:02

标签: swift uitableview

我有一个Dynamic Prototype表,它也有一些静态单元格。我试图允许其中一个静态单元格在单个单元格中有两个文本字段。我相信这样做,我需要为每个文本字段设置标签。

但是,我不确定如何(如果可能的话)将标签分配给下面的行。

TableViewController:

x_data = [1., 2., 3., 4.]
y_data = [2., 4., 6., 8.]

两个TableViewCells

    case DiveMasterIndex:
        cell = tableView.dequeueReusableCellWithIdentifier(Resource.DiveMasterCell)
        (cell as! DiveMasterTableViewCell).textField.placeholder = Strings.DiveMaster.localized // tag 1001

    case DiveMasterIDIndex:
        cell = tableView.dequeueReusableCellWithIdentifier(Resource.DiveMasterCell)
        (cell as! DiveMasterIDTableViewCell).textField.placeholder = Strings.DiveMasterID.localized // tag 1002

第二个

class DiveMasterTableViewCell: UITableViewCell, UITextFieldDelegate
{

@IBOutlet var textField: UITextField!

override func awakeFromNib()
{
    super.awakeFromNib()
}


override func setSelected(selected: Bool, animated: Bool)
{
    super.setSelected(selected, animated: animated)
}


func textFieldDidEndEditing(textField: UITextField)
{

    (self.tableViewController as! DiveDetailsNew2TableVC).diveModel.name = textField.text!
}

1 个答案:

答案 0 :(得分:1)

如果您希望一个单元格有2个文本字段,那么更好的方法是为文本字段创建具有不同名称的2个出口,而不是为它们分配标记。对于这种情况,您不需要2个单元格。