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
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.
Still existing in 3.3.GA and making delete-events impossible.
Hans, try to use itemId to determine which item is being deleted INSTEAD OF using itemIndex
Thank you, solved for me!
Closing ticket as invalid with reference to previous comments.