13

Titanium で iPhone アプリケーションを開発しており、特定のTableViewSectionに行を追加する必要があります。アプリケーションのライフサイクル全体でユーザーによって動的に行われるため、ページの読み込み時にこれを行うことはできません。ドキュメントには、TableViewSection にaddは 2 つの引数を取るメソッドがあると書かれていますが、機能させることはできません。これが私の既存のコードです:

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

これは 1 つの引数を渡すだけであり、Titanium はキャッチされない例外で終了します。

2010-04-26 16:57:18.056 MyApplication[72765:207] *** Terminating app due to uncaught 
exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in 
section 2. The number of rows contained in an existing section after the update (2) must be 
equal to the number of rows contained in that section before the update (1), plus or minus the 
number of rows inserted or deleted from that section (0 inserted, 0 deleted).'
2010-04-26 16:57:18.056 MyApplication[72765:207] Stack: (

例外は行を追加したように見えますが、何らかの理由で許可されていません。ドキュメントにはTableViewSection、「ビュー」と「行」を取り込むと記載されているため、次のことを試しました。

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

上記のコードは例外をスローしませんが、次のようになります[WARN]

[WARN] Invalid type passed to function. expected: TiUIViewProxy, 
was: TiUITableViewRowProxy in  -[TiUITableViewSectionProxy add:] (TiUITableViewSectionProxy.m:62)

appendRowTableViewSections は、 またはのようなメソッドをサポートしていないようですinsertRow。そのため、他にどこに行くべきかわかりません。KitchenSink アプリを調べましたが、TableViewSection に行を追加する例は見つかりませんでした。どんな助けでも大歓迎です。

4

3 に答える 3

4

私は自分でこの問題と戦ってきましたが、多くの試行錯誤の末、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);

幸運を!

于 2010-11-07T19:08:29.143 に答える
1

for add メソッドの外でビューを作成しようとしましたか? コンストラクターの問題である可能性があります。

for ループの外側に一般的なビューを作成してみて、警告メッセージが表示されるかどうかを確認してください。

于 2010-04-29T13:51:46.773 に答える
0

リワインダーが言ったことはうまくいきます。これは、より単純な形式で提示された、機能する同様のトリックです。TableViewSectionに新しい行を追加した後、次の(一見ばかげている)ステートメントを含めます。

$.table.data = $.table.data

HTH

于 2013-03-03T21:28:10.327 に答える