Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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

— asked March 17th 2010 by Mark Beech
  • reuse
  • tableview
0 Comments

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.

    — answered March 17th 2010 by Allen Firstenberg
    permalink
    0 Comments
  • Which platform and how are you updating the TableView?

    — answered March 17th 2010 by Don Thorp
    permalink
    0 Comments
  • 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.

    — answered March 17th 2010 by Chris Reed
    permalink
    0 Comments
  • 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

    — answered March 18th 2010 by Mark Beech
    permalink
    0 Comments
  • 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.)

    — answered March 18th 2010 by Allen Firstenberg
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.