Home Swift UITableView how to retain edited values on scroll
Reply: 1

Swift UITableView how to retain edited values on scroll

user3048440
1#
user3048440 Published in 2017-11-14 18:40:17Z

I am following this link https://medium.com/ios-os-x-development/ios-how-to-build-a-table-view-with-multiple-cell-types-2df91a206429 to generate dynamic fields in a uitableview by reading a JSON array , what I am changing in that example is instead of just displaying the data I am making the labels as editable making it a UITextField, I understand that a tableview regenerates each cell that goes on and off the view. I would like to understand how to retain the edited values in each cell.

Pavel Belder
2#
Pavel Belder Reply to 2017-11-15 00:51:59Z

Basically, the table view is supposed to present the data of a data source.

In your case (in the medium example) the data source is of type ProfileViewModel which holds an array of items of type ProfileViewModelItem. Every cell presents the data of a single ProfileViewModelItem .

The way to retain the edited values is to change the item which is presented by the cell who's text field is being edited.

So every time a user types in a text field , you should change the data in the item (ProfileViewModelItem) which is holding the text that is being shown by the text field. That way the text field and the item are in sync and if the cell goes away , when it comes back on the screen , the text field will show the same text that is in the item , which is the same text that last appeared on the text field when the cell was last on screen.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.334267 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO