Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17028] iOS: ListView delete event returning incorrect data

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionInvalid
Resolution Date2014-06-30T18:20:36.000+0000
Affected Version/sRelease 3.2.2, Release 3.2.3
Fix Version/sn/a
Componentsn/a
LabelssupportTeam
ReporterMarco Cota
AssigneeIngo Muschenetz
Created2014-05-26T19:39:40.000+0000
Updated2017-03-22T21:47:48.000+0000

Description

Issue

In iOS when using the property "canEdit:true" in a template and deleting a row to catch the "delete event" the data received is from the listView state after the user action, even when the documentation mention that this information will return the data from before the user action. "Note that the sectionIndex and itemIndex properties of this event correspond to the List View state before the user action."

Steps to repro

1. Open the test case 2. Swipe on any of the rows 3. Click the delete button Expected Result: The alert will show the information of the row that has been deleted. Actual Result: The alert shows the information form the row that takes the position of the deleted row.

Sample Code

var aWindow = Ti.UI.createWindow({
	title : "ListView Delete",
	backgroundColor : 'white'
});
var itemTemplate = {
	childTemplates : [{
		type : 'Ti.UI.Label',
		bindId : 'lblText',
		properties : {
			top : 20,
			bottom : 20,
			color : 'black',
			width : Ti.UI.SIZE,
			height : Ti.UI.SIZE
		}
	}]
};

var listItems = [];
for (var i = 0; i < 20; i++) {
	listItems.push({
		lblText : {
			text : i + ' samll'
		},
		properties : {
			id : i,
			backgroundColor : 'white',
			canEdit : true,
			height : Ti.UI.SIZE,
			selectedBackgroundColor : 'gray'
		}
	});

}
var listSection = Ti.UI.createListSection({
	items : listItems
});
var listView = Ti.UI.createListView({
	templates : {
		'itemTemp' : itemTemplate
	},
	defaultItemTemplate : 'itemTemp',
	sections : [listSection]
});

listView.addEventListener('delete', itemDelete);

function itemDelete(e) {
	alert("itemDetails>>" + JSON.stringify(e.section.getItemAt(e.itemIndex)));
}

aWindow.add(listView);
aWindow.open();

Documentation

http://docs.appcelerator.com/titanium/latest/#!/api/Titanium.UI.ListView-event-delete

Comments

  1. Vishal Duggal 2014-06-30

    The documentation is correct. The sectionIndex and itemIndex do correspond to listview state before the user action. There is no sectionIndex or itemIndex for the item after it has been deleted from the listview. The two properties are sent out for the developer to update their data set on the javascript side. Listview automatically updates its internal data set on delete event. Querying the listview or section for deleted data is incorrect.
  2. Hans Knöchel 2014-07-22

    Still existing in 3.3.GA and making delete-events impossible.
  3. David He 2014-07-22

    Hans, try to use itemId to determine which item is being deleted INSTEAD OF using itemIndex
  4. Hans Knöchel 2014-07-29

    Thank you, solved for me!
  5. Lee Morris 2017-03-22

    Closing ticket as invalid with reference to previous comments.

JSON Source