Problem
insertRowBefore adds rows at the incorrect spot.
Reproduction
Drop the following in an app.js.
1. It has a table with two rows: A and C.
2. It attempts to insert a row B before C.
3. The rows end up being BAC, instead of the expected ABC.
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
win.open();
var data = [
{ title: 'A', name: 'A' },
{ title: 'C', name: 'C' }
];
var tableview = Ti.UI.createTableView({ data: data });
win.add(tableview);
function checkIndex(name, expected) {
var actual = tableview.getIndexByName(name);
Ti.API.info(name + "'s Index: " + actual);
if (actual != expected) {
alert(name + ' has an inaccurate index! expected: ' + expected + ', actual: ' + actual);
}
}
setTimeout(function() {
tableview.insertRowBefore(tableview.getIndexByName('C'), { title: 'B', name: 'B' });
checkIndex('A', 0);
checkIndex('B', 1);
checkIndex('C', 2);
}, 1000);
Expected Behavior
Calling "insertRowBefore" a row should insert the row before the specified row. It should _not_ insert the row two rows before the specified row.
This is expected behavior.
In this case following code behaves the same:
It insert both lines before the first record. What is worse - it is impossible to insert row before last row. So as a developer I expect that following two lines must behave the same for i > 0:
As for me this is a bug and should be fixed
Updated ticket for better formatting and clarity of purpose.
pull # 298 pending
Tested with 1.8.0.v20110819142548 iPhone 4.3.4 iPad2 4.3.2 Motorola Xoom 3.2 Nexus One 2.2.2