Titanium Community Questions & Answer Archive

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

Remove a TableView from a function

I created a function:

var newsTopic = function()
   var tableview = Ti.UI.createTableView({
      backgroundColor: '#fff'


and ran the function


I have a button and when it's clicked I would like that table view to be removed.

I've tried:

btn.addEventListener('click', function()

but when I run the app it crashes. I'm guess it's because the TableView is the in the function. How can I remove the TableView?

— asked August 17th 2010 by Chris Schultz
  • android
  • function
  • remove
  • tableview

1 Answer

  • Accepted Answer

    The scope of tableView it's private ( it's declared inside the function). So when you try to remove the tableview, there is nothing to remove.

    Take the var out of function

    var tableview;
    var newsTopic = function()
       tableview = Ti.UI.createTableView({

    Untested but should work.

    — answered August 17th 2010 by Dan Tamas
    • Perfect. Thanks!

      — commented August 17th 2010 by Chris Schultz
    • how can I check if tableView exists in this case before removing?

      — commented March 25th 2012 by George Georgiou
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.