Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-5035] iOS: TableView insertRowBefore index

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionCannot Reproduce
Resolution Date2013-05-09T05:03:17.000+0000
Affected Version/sRelease 1.7.2
Fix Version/s2013 Sprint 10
ComponentsiOS
Labelsinsertafter, insertbefore, ios, table_view, tableviewrow
ReporterEduardo Gomez
Assigneejithinpv
Created2011-08-17T13:09:32.000+0000
Updated2017-03-21T22:21:49.000+0000

Description

Problem

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).

Repro Sequence

// 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);
});

Console output

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}

Associated HD ticket

http://appc.me/c/APP-341733

Attachments

FileDateSize
iOS Simulator Screen shot Jun 20, 2013 3.13.01 PM.png2013-06-20T09:40:46.000+000020715
iOS Simulator Screen shot May 8, 2013 10.34.54 PM.png2013-05-09T05:05:13.000+000018092
Rows.jpg2011-08-17T13:09:32.000+000038437

Comments

  1. jithinpv 2013-05-09

    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
  2. jithinpv 2013-06-20

    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
  3. Lee Morris 2017-03-21

    Closing ticket as the issue cannot be reproduced and due to the above comments.

JSON Source