0

I am attempting to update my table view with updated data but whenever I try to clear it using either

tagsTable.setData();
or
tagsTable.setData([]);
or
tagsTable.data = null;

and then re-apply the updated data using

tagsTable.setData(TagsData);

It never clears the table originally so the new data is just added to the end of the table, so I have the old data as well as the new data in the 1 table.

Any one know whats wrong or how to fix it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Follett
  • 11
  • 2
  • 2
    can i see how are you updating the data in `TagsData` ? you have to clear it `TagsData=[]` before adding newest data... – LHIOUI Oct 06 '14 at 08:08

1 Answers1

0

Here's a simple (classic Titanium) app that shows clearing and re-filling the table's data property via some buttons. I'd triple-check the validity of your TagsData sections/rows to make sure everything within the array is being set properly.

var
    win = Ti.UI.createWindow({
        title: "Table Funs",
        layout: "vertical",
        backgroundColor: "#ffffff"
    }),
    navwin = Ti.UI.iOS.createNavigationWindow({
        window: win
    }),
    table = Ti.UI.createTableView(),
    clearButton = Ti.UI.createButton({
        title: "Clear Table",
        width: Ti.UI.FILL,
        height: 44,
        backgroundColor: "#f4f4f4",
        color: "red",
        bottom: 1
    }),
    fillButton = Ti.UI.createButton({
        title: "Fill Table",
        width: Ti.UI.FILL,
        height: 44,        
        backgroundColor: "#f4f4f4",
        color: "blue",
        bottom: 1
    }),
    tableData = [];

// Fill up tableData array with rows
tableData.push(Ti.UI.createTableViewRow({ title: "Hey" }));
tableData.push(Ti.UI.createTableViewRow({ title: "this" }));
tableData.push(Ti.UI.createTableViewRow({ title: "is" }));
tableData.push(Ti.UI.createTableViewRow({ title: "a" }));
tableData.push(Ti.UI.createTableViewRow({ title: "table" }));

clearButton.addEventListener("click", function() {
    Ti.API.debug("Clicked clear button.");
    table.setData(null);
    return;
});

fillButton.addEventListener("click", function() {
    Ti.API.debug("Clicked fill button.");
    table.setData(tableData);
    return;
});

// Fill table with our data
table.setData(tableData);

// Build window
win.add(clearButton);
win.add(fillButton);
win.add(table);

navwin.open();
Kip
  • 170
  • 3