Titanium Community Questions & Answer Archive

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

Delete all rows in a tableview with a single click

Hi there,

has anyone a good way to "clear" the table?
I want to build a button which deletes all my rows, so that i can add some new data in my tableview.

— asked August 3rd 2010 by Michael Gajda
  • button
  • clear
  • delete
  • iphone
  • mobile
  • table
  • tablerow
  • tableview

3 Answers

  • An easy way to clear all the rows in a table is:


    That said, you only need to do this if you will then be appending or inserting rows to the table. Another alternative is to instead create an array of table rows, then use setData(myArray). This swaps out the previous collection of table rows for the data in they new array.

    — answered July 26th 2011 by Doug Handy
    1 Comment
    • In this vein, I need to totally remove my db (sqllite) from the emulator app, as I made changes to the design and need to reinstall it. I cannot find the file to delete manually (which I would like to identify) but a programmatic solution would also be great. I'm using Ti 1.7.2. Thanks,

      — commented October 11th 2011 by Patty Mapes
  • Dough, If I use "myTable.setData([])" all the objects in the table are removed from memory?

    — answered March 15th 2012 by Javier Hdez
    1 Comment
    • I can't answer definitively how / when the garbage collection does its thing. I use this technique all the time though. Bear in mind that if you previously used myTable.setData(myArray[]) and you have not also cleared out myArray[], that as long as myArray[] remains in scope it still has the data.

      — commented March 15th 2012 by Doug Handy
  • am also wondering about this one…

    — answered July 25th 2011 by Peter Eman Abastillas
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.