Adding UITableView row seems to replace another

Hi,


I have a dynamic UITableView and I let the user insert rows as they need.


The problem is, since its reusable, after enough rows are added, it resuses the cells. so eventually the last added row takes the info from the first row and the first row is reset to empty.


I was not expecting this behaviour as I was hoping, The table would resuse what only if I deallocated the row. It seems I just move down long enough that it row is off screen and therefore reuseable.


I need to maintain all rows so that in the end I can do a for loop and grab all the information.


In the example below, the last row "light turk" is actually the first row I added to the table (not seen on screen).


Accepted Reply

Sure, by saying "data model" it does not need to be core data or something. Just a plain NSArray could by sufficient. When the user enters text, you should store the entered text into an NSString in an NSArray. One entry per row. Starting with an empty array when the view appears and on save you just loop through that array and do what ever you need to do.


UITableViewCell objects are not meant to store information. They are just for displaying information which are stored somewhere else.


Dirk

Replies

Hi,


you should seperate your data model from the UITableViewRows. If the user inserts a new row you should insert both a new UITableViewCell and e.g. add an entry into an NSArray.


Dirk

Hello,


I would usually do that but I dont have a data model, its a dynamic table as you see above and its all user driven. They enter the information and when they click save, I get each cell and get the text and such.


Edit: Noticed screenshot is not showing, seems it needs approval

Sure, by saying "data model" it does not need to be core data or something. Just a plain NSArray could by sufficient. When the user enters text, you should store the entered text into an NSString in an NSArray. One entry per row. Starting with an empty array when the view appears and on save you just loop through that array and do what ever you need to do.


UITableViewCell objects are not meant to store information. They are just for displaying information which are stored somewhere else.


Dirk

As suggested here and in various other forums, it seems one has to really implement a data sourc even if all the infromation was user drive. Here are the steps I took


- Added a dataObject for the first row that I have in my tableView (it comes with one row)

- When the user adds/deletes/moves a row, I handle either creating/deleting/moving the corrpesonding dataObject

- When the user enters information in the various textFields, I update the corrpesonding dataObject.


This works find, though unneccesary and adds some weight. And Its easier said than done.