How to append a row to a TableViewSection in Titanium?
- by Mike Trpcic
I'm developing an iPhone application in Titanium, and need to append a row to a particular TableViewSection. I can't do this on page load, as it's done dynamically by the user throughout the lifecycle of the application. The documentation says that the TableViewSection has an add method which takes two arguments, but I can't make it work. Here's my existing code:
for(var i = 0; i <= product_count; i++){
productsTableViewSection.add(
Ti.UI.createTableViewRow({
title:'Testing...'
})
);
}
That is just passing one argument in, and that causes Titanium to die with an uncaught exception:
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: (
The exception looks like it did add the row, but it's not allowed to for some reason. Since the documentation says that TableViewSection takes in "view" and "row", I tried the following:
for(var i = 0; i <= product_count; i++){
productsTableViewSection.add(
Ti.UI.createView({}),
Ti.UI.createTableViewRow({
title:'Testing...'
})
);
}
The above code doesn't throw the exception, but it gives a [WARN]:
[WARN] Invalid type passed to function. expected: TiUIViewProxy,
was: TiUITableViewRowProxy in -[TiUITableViewSectionProxy add:] (TiUITableViewSectionProxy.m:62)
TableViewSections don't seem to support any methods like appendRow, or insertRow, so I don't know where else to go with this. I've looked through the KitchenSink app, but there are no examples that I could find of adding a row to a TableViewSection. Any help is appreciated.