Remove a TableView from a function
I created a function:
var newsTopic = function()
{
var tableview = Ti.UI.createTableView({
data:data,
top:68,
backgroundColor: '#fff'
});
news.add(tableview);
}
and ran the function
newsTopic();
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()
{
news.remove(tableview);
});
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?
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.