[TIMOB-540] Tableview.insertRowBefore(index, row, options) Inserts in wrong Index
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2011-10-27T15:52:02.000+0000 |
Affected Version/s | Release 1.6.2, Release 1.7.1 |
Fix Version/s | Sprint 2011-31, Release 1.8.0 |
Components | iOS |
Labels | tableview, tableviewrow |
Reporter | Dawson Toth |
Assignee | Sabil Rahim |
Created | 2011-04-15T02:31:27.000+0000 |
Updated | 2011-10-27T15:52:02.000+0000 |
Description
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.Comments
- Stephen Tramer 2011-04-15
This is expected behavior.
- Andrew Kulinich 2011-06-13
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:tableview.insertRowBefore(0, { title: '0' }); tableview.insertRowBefore(1, { title: '1' });
As for me this is a bug and should be fixedtableview.insertRowBefore(i, { title: '0' }); tableview.insertRowAfter(i-1, { title: '0' });
- Dawson Toth 2011-07-14 Updated ticket for better formatting and clarity of purpose.
- Sabil Rahim 2011-07-27 pull # 298 pending
- Natalie Huynh 2011-08-25 Tested with 1.8.0.v20110819142548 iPhone 4.3.4 iPad2 4.3.2 Motorola Xoom 3.2 Nexus One 2.2.2