我在UITableViewCell中创建一个窗体,此窗体在原型单元格中具有标签和文本字段。在这里看到它的图片 TableView Story board Image。 我使用标识符动态创建的形式,我的代码是UITableViewCell滚动后的数据更改
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("protocell", forIndexPath: indexPath) as! UITableViewCell
var lable = cell.viewWithTag(1) as! UILabel
lable.text = details[indexPath.row]
lable.textColor = UIColor.brownColor().colorWithAlphaComponent(0.7)
var textfield = cell.viewWithTag(2) as! UITextField
textfield.placeholder = "Enter \(details[indexPath.row])"
self.arrayTextField.append(textfield)
if details[indexPath.row] == "Name" {
textfield.placeholder = "Enter First \(details[indexPath.row]) Middle \(details[indexPath.row]) Last \(details[indexPath.row]) "
}
textfield.backgroundColor = UIColor.redColor().colorWithAlphaComponent(0.2)
return cell
}
现在的问题是我有18个字段,并且当我在字段中输入值和滚动视图以填充剩余的字段,则值更改字段中的更改。 请帮忙。
您需要跟踪数据源中哪些文本字段包含文本。所以当在tableView:(tableView:cellForRowAtIndexPath:)中有一个时,你放了它,否则,你放置你的placeHolder,因为单元格被重用。 – Larme
**从不**使用包含表格视图单元的UI元素的数组('arrayTextField')。这可能是你的问题的原因。考虑改进(数据源)模型的设计,更改模型中的数据并重新加载表视图。 – vadian
跟踪我使用'arrayTextField'的数据源@Larme如何跟踪数据源以查看哪个文本字段有文本。我搜查了但没有发现任何东西。 – knownUnknown