Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将一行附加到Tianium中的TableViewSection?_Javascript_Iphone_Titanium - Fatal编程技术网

Javascript 如何将一行附加到Tianium中的TableViewSection?

Javascript 如何将一行附加到Tianium中的TableViewSection?,javascript,iphone,titanium,Javascript,Iphone,Titanium,我正在用钛合金开发一个iPhone应用程序,需要在特定的。我不能在页面加载时这样做,因为它是由用户在应用程序的整个生命周期中动态完成的。文档中说TableViewSection有一个采用两个参数的add方法,但我不能让它工作。以下是我现有的代码: for(var i = 0; i <= product_count; i++){ productsTableViewSection.add( Ti.UI.createTableViewRow({ t

我正在用钛合金开发一个iPhone应用程序,需要在特定的。我不能在页面加载时这样做,因为它是由用户在应用程序的整个生命周期中动态完成的。文档中说TableViewSection有一个采用两个参数的
add
方法,但我不能让它工作。以下是我现有的代码:

for(var i = 0; i <= product_count; i++){
    productsTableViewSection.add(
        Ti.UI.createTableViewRow({
            title:'Testing...'
        })
     );
}
异常看起来像是添加了行,但由于某些原因不允许添加行。由于文档中说,
TableViewSection
包含“视图”和“行”,因此我尝试了以下方法:

for(var i = 0; i <= product_count; i++){
    productsTableViewSection.add(
        Ti.UI.createView({}),
        Ti.UI.createTableViewRow({
            title:'Testing...'
        })
     );
}

TableViewSections似乎不支持任何方法,如
appendRow
,或
insertRow
,因此我不知道还有什么其他方法可以使用。我已经浏览了KitchenSink应用程序,但是没有找到向TableViewSection添加行的示例。非常感谢您的帮助。

您是否尝试过在for add方法之外创建视图?看来这可能是一个构造函数问题


尝试在for循环之外创建一个通用视图,看看这是否能让您通过警告消息

我自己也曾处理过这个问题,经过多次尝试和错误,我发现在TableViewSection的封闭TableView上设置数据是必要的:

var win = Ti.UI.currentWindow;
var tableview = Ti.UI.createTableView();
var sec1 = Titanium.UI.createTableViewSection();
var sec2 = Titanium.UI.createTableViewSection();
var data = [];

for(var v=0; v<=10; v++) {
    var row = Ti.UI.createTableViewRow({
        title:'Section 1 row '+v,
        className:'sectionrow'
    });
    sec1.add(row);
}
for(var c=0; c<=10; c++) {
    var row = Ti.UI.createTableViewRow({
        title:'Section 2 row '+c,
        className:'sectionrow'
    });
    sec2.add(row);
}

data[0] = sec1;
data[1] = sec2;
tableview.data = data;

win.add(tableview);

setTimeout(function() {
    alert('Adding additional rows to section 1');
    for(var x=0; x<=5; x++) {
        var row1 = Ti.UI.createTableViewRow({
            title:'Section 1 additional row '+x,
            className:'sectionrow'
        });
        sec1.add(row1);
    }
    alert('Adding additional rows to section 2');
    for(var y=0; y<=5; y++) {
        var row2 = Ti.UI.createTableViewRow({
            title:'Section 2 additional row '+y,
            className:'sectionrow'
        });
        sec2.add(row2);
    }
    // this is the line that makes the magic happen!
    tableview.data = data;
}, 3000);
var-win=Ti.UI.currentWindow;
var tableview=Ti.UI.createTableView();
var sec1=Titanium.UI.createTableViewSection();
var sec2=Titanium.UI.createTableViewSection();
var数据=[];

对于(var v=0;v,rewinder所说的很有效。下面是一个类似的技巧,以更简单的形式呈现。在将新行添加到TableViewSection后,包括以下(看似愚蠢的)语句:

$.table.data = $.table.data

var win = Ti.UI.currentWindow;
var tableview = Ti.UI.createTableView();
var sec1 = Titanium.UI.createTableViewSection();
var sec2 = Titanium.UI.createTableViewSection();
var data = [];

for(var v=0; v<=10; v++) {
    var row = Ti.UI.createTableViewRow({
        title:'Section 1 row '+v,
        className:'sectionrow'
    });
    sec1.add(row);
}
for(var c=0; c<=10; c++) {
    var row = Ti.UI.createTableViewRow({
        title:'Section 2 row '+c,
        className:'sectionrow'
    });
    sec2.add(row);
}

data[0] = sec1;
data[1] = sec2;
tableview.data = data;

win.add(tableview);

setTimeout(function() {
    alert('Adding additional rows to section 1');
    for(var x=0; x<=5; x++) {
        var row1 = Ti.UI.createTableViewRow({
            title:'Section 1 additional row '+x,
            className:'sectionrow'
        });
        sec1.add(row1);
    }
    alert('Adding additional rows to section 2');
    for(var y=0; y<=5; y++) {
        var row2 = Ti.UI.createTableViewRow({
            title:'Section 2 additional row '+y,
            className:'sectionrow'
        });
        sec2.add(row2);
    }
    // this is the line that makes the magic happen!
    tableview.data = data;
}, 3000);
$.table.data = $.table.data