Reusing a tableview
I have an mobile app that uses a table view.
The js file used for the table view is generic, and it just loads data via JSON determined via a variable passed from a button press.
All work fine, except this….
Say i click on a button that returns a table view with 8 rows, then i go back and click a button that returns a table view with 4 rows. I still get a table with 8 rows, the first 4 rows are filled with new data and the last 4 rows being empty.
How can i "reset" the view so it starts from scratch each time i need to generate the table view?!
Thanks
5 Answers
-
Accepted Answer
Try clearing out the TableView first. I've had mixed luck with this, which I'm assuming is a race condition or timing issue. But try clearing the table with
tableView.setData( [] );
first before setting your data again.
-
Which platform and how are you updating the TableView?
-
Hi Mark,
Be mindful of the event in which the setData command is in. You may need to plant it in a window focus event, since the page might be 'cached' and not firing load code. May be useful to put an obvious Ti.API.Info('Focus Event'); to report in developer that the focus event is indeed firing when you expect it to.
Cheers,
Chris. -
Thanks for the replys guys.
I think i have figured this one out.
It is actually my limited understanding of the table view. I didn't realize that if for instance you only had 3 rows in a table, the table view would still fill the entire height of the screen, and draw the separators on the unfilled rows.
My solution is to just change the separator color to the same color as the background.
At least i think that is the situation unless anyone knows otherwise
-
Ahhhh… yes. Siminarly you can set the separatorStyle attribute on the TableView to "none". (For the iPhone, this can be done with Titanium.UI.iPhone.TableViewSeparatorStyle.NONE. I'm not sure if there is an equivalent android value yet.)