It looks like 'insertRowBefore' is 1-index-based, insertRowBefore(1) will insert a row before the row at position 0 (first item).
So it would be expected insertRowBefore(1) to insert a row before the row at position 1 (see screenshot attached).
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff'
});
var tab1 = Titanium.UI.createTab({
icon : 'KS_nav_views.png',
title : 'Tab 1',
window : win1
});
//
// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({
title : 'Tab 2',
backgroundColor : '#fff'
});
var tab2 = Titanium.UI.createTab({
icon : 'KS_nav_ui.png',
title : 'Tab 2',
window : win2
});
//
// add tabs
//
tabGroup.addTab(tab1);
tabGroup.addTab(tab2);
var table = Ti.UI.createTableView({
});
var i, len = 2;
var rows = [];
var row;
for( i = 0; i <= len; i++) {
row = Ti.UI.createTableViewRow({
height : 50,
className : 'tableRow',
touchEnabled : true,
focusable : true,
});
row.add(Ti.UI.createLabel({
text : 'Row ' + i
}));
rows.push(row);
};// For
table.setData(rows);
win1.add(table);
var button = Ti.UI.createButton({
title : 'Add Row - insertRowBefore 1',
top : 25,
height : 25
});
button.addEventListener('click', function() {
var newRow1 = Ti.UI.createTableViewRow({
height : 50,
className : 'tableRow',
touchEnabled : true,
focusable : true
});
newRow1.add(Ti.UI.createLabel({
text : 'New Row inserted before position 1'
}));
table.insertRowBefore(1, newRow1);
});
win2.add(button);
var button2 = Ti.UI.createButton({
top: 125, height:25, title : 'Add Row - insertRowAfter 1',
});
button2.addEventListener('click',function(){
var newRow2 = Ti.UI.createTableViewRow({
height : 50,
className : 'tableRow',
touchEnabled : true,
focusable : true
});
newRow2.add(Ti.UI.createLabel({
text : 'New Row inserted After position 1'
}));
table.insertRowAfter(1, newRow2);
});
win2.add(button2);
// open tab group
tabGroup.open();
table.addEventListener('click', function(e)
{
var myIndex = e.index;
Ti.API.info('Current Indices: '+ myIndex);
});
Clicked the Table view Rows in order to retrieve current indices
{noformat}
[INFO] Current Indices: 0
[INFO] Current Indices: 1
[INFO] Current Indices: 2
{noformat}
cannot reproduce Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 iOS iPhone Simulator: iOS SDK version: 6.0
Issue does not reproduces Tested with iOS SDK: 5.1 iOS iPhone Simulator: 5.1 Mac OS X Version 10.7.5 Titanium SDK version 3.1.1.v20130606121419 Titanium Studio, build: 3.0.1.201212181159
Closing ticket as the issue cannot be reproduced and due to the above comments.