【问题标题】:Attempting to clear tableView just doubles the content尝试清除 tableView 只会使内容翻倍
【发布时间】:2014-10-06 00:49:27
【问题描述】:

我正在尝试使用更新的数据来更新我的表格视图,但每当我尝试使用任一方法清除它时

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

然后使用

重新应用更新的数据
tagsTable.setData(TagsData);

它最初从不清除表,所以新数据只是添加到表的末尾,所以我在 1 个表中拥有旧数据和新数据。

有谁知道问题出在哪里或如何解决?

【问题讨论】:

  • 我可以看看你如何更新TagsData 中的数据吗?在添加最新数据之前,您必须清除它TagsData=[]...

标签: ios uitableview titanium titanium-studio


【解决方案1】:

这是一个简单的(经典 Titanium)应用程序,显示通过一些按钮清除和重新填充表格的 data 属性。我会三次检查您的 TagsData 部分/行的有效性,以确保数组中的所有内容都设置正确。

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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 2021-11-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多