The problem
"TableView" component does not calculate number of rows well. It seems it counts rows from last section only. That cause issues when row is being updated or deleted by row index.
Test case
To see this issue, run this example:
(function() {
var win = Ti.UI.createWindow({
backgroundColor: '#000',
navBarHidden: true
});
var tableView = Ti.UI.createTableView();
var tableViewSection1 = Ti.UI.createTableViewSection({
headerTitle: 'Section 1'
});
var rows = [];
for (var i = 0; i < 10; ++i) {
rows[i] = Ti.UI.createTableViewRow({ title: 'Row ' + i });
tableViewSection1.add(rows[i]);
}
var tableViewSection2 = Ti.UI.createTableViewSection({
headerTitle: 'Section 2'
});
rows = [];
for (i = 0; i < 20; ++i) {
rows[i] = Ti.UI.createTableViewRow({ title: 'Row ' + (i + 10) });
tableViewSection2.add(rows[i]);
}
tableView.setData([ tableViewSection1, tableViewSection2 ]);
tableView.addEventListener('click', function(e) {
tableView.updateRow(e.index, Ti.UI.createTableViewRow({ title: 'NEW Row' }));
});
win.add(tableView);
win.open();
})();
Click on "Row 11" in second section. You'll see that "Row 21" is updated.
Now click on "Row 23" and you should get exception that says that index is invalid.
Expected behavior
Row that is clicked should also be updated.
This works fine on iOS, and does not work on Android even prior to 2.1 (I tested with 1.8.3).
IMHO, this issue should have bigger priority because there is no workaround and updating/deleting wrong row or crushing the app (if index is out of range) as the result of this issue is a big thing from usability point of view. Don't know how many developers use update/delete functionality, but it seems pretty basic thing to me.
Thanks. :)
Pull request is https://github.com/appcelerator/titanium_mobile/pull/2623
Verified fixed with mobile sdk-2.2.0.v20120810080115 Titanium Studio, build: 2.1.1.201207271312 Device: Galaxy S III Android version 4.0.4
Row 0 of Section 1 does not change,instead the first row of section 2 i.e. row 10 changes on click of row 0. Verified on: Tested with Titanium Studio:2.1.2.201208301612 Tested with Titanium SDK: 2.2.0.v20120831200114
It appears that a recent change here re-introduced a bug. Pull Request https://github.com/appcelerator/titanium_mobile/pull/2880
Verified with: SDK: 3.0.0.v20120910184912 STUDIO: 2.1.3.201209071738 Device: Samsung galaxy tab(v 3.2)