My first line of writing Copy itself to the bottom lines
And when I scroll, Places of data are changing
My first line of writing Copy itself to the bottom lines
And when I scroll, Places of data are changing
Data in UITableView Cell is repeated because Cell is reused so you will need to keep track of data for cell, may be you can add data in array arranged by index.
Yes thats the concept of UITableview dequeCells: as it reuses cells , so if there are say 100 entries only limited number of cells will be created at a time in order to save memory. Now in order to avoid it, fill your cell views with datasource that has all the values. If you see that some values are missing from datasource, just use, for example:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Tek101TableViewCell
cell.selectionStyle = .none
cell.siraLabel.text = ""
cell.siraLabel.text = String(indexPath.row + 1) + ")"
return cell
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Tek101TableViewCell
cell.selectionStyle = .none
cell.siraLabel.text = String(indexPath.row + 1) + ")"
return cell
}
You need to set value in textfield delegate method as below :(As per your need)
If you are use return button in keyboard
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
let cell = textField.superview?.superview as! Tek101TableViewCell // track you view hierarchy
cell. siraLabel?.text = textField.text
textField.resignFirstResponder()
return true
}
If you want to track value end editing method
func textFieldDidEndEditing(_ textField: UITextField){
let cell = textField.superview?.superview as! Tek101TableViewCell // track you view hierarchy
cell. siraLabel?.text = textField.text
}
In UITablview
cell is reused so this thing will happen. To solve this issue you have to keep all the records inside one global array variable.
You can store all input in array or dictionary while user insertion. and then you have to give this array values to each and every cell from CellForRow
.
In short you have to deal with array only.
Hope this will help you.