Project: titanium
Issue TIMOB-20389: iOS: Listview delete event sends wrong itemId
In TiUIListView.m code has been refactored a couple of months ago (?) to fire edit events in 1 place. For delete this is causing quite a big problem because now the order of events has changed. TiUIListView.m, around line 1045 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath Before the change: - A reference to the deleted item was stored - The actual delete was performed on the listview - The event for the JS client was build and sent using the previously stored itemId After the change: - The item is actually deleted from the listview. - The fireEditEventWithName method is called to trigger the JS event. The problem: The fireEditEventWithName gets a reference to the item (and thus the itemId) at a section index and itemindex, but since the item was already deleted it gets the wrong or no item. If my findings are correct you have created quite a big invisible bug deleting wrong items all over the world... {code:title=Sample.JavaScript|borderStyle=solid} //FirstView Component Constructor function FirstView() {	//create object instance, a parasitic subclass of Observable	var self = Ti.UI.createView();	var listView = Ti.UI.createListView({	editing: true,	allowsSelection: true	});	var sections = [];	var fruitSection = Ti.UI.createListSection({ headerTitle: 'Fruits'});	var fruitDataSet = [	{properties: { itemId: "apple", title: 'Apple', canEdit: true}},	{properties: { itemId: "banana", title: 'Banana', canEdit: true}},	];	fruitSection.setItems(fruitDataSet);	sections.push(fruitSection);	var vegSection = Ti.UI.createListSection({ headerTitle: 'Vegetables'});	var vegDataSet = [	{properties: { itemId: "carrots", title: 'Carrots', canEdit: true}},	{properties: { itemId: "potatoes", title: 'Potatoes', canEdit: true}},	];	vegSection.setItems(vegDataSet);	sections.push(vegSection);	listView.sections = sections;	self.add(listView);	var fishSection = Ti.UI.createListSection({ headerTitle: 'Fish'});	var fishDataSet = [	{properties: { itemId: "cod", title: 'Cod', canEdit: true}},	{properties: { itemId: "haddock", title: 'Haddock', canEdit: true}},	];	fishSection.setItems(fishDataSet);	listView.appendSection(fishSection);	listView.addEventListener("delete", function(e) {	alert(e.itemId);	});	return self; } module.exports = FirstView; {code}
Story points: 8