我在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