Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-20389

iOS: Listview delete event sends wrong itemId

    Details

    • Story Points:
      8
    • Sprint:
      2016 Sprint 3 SDK

      Description

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

      Sample.JavaScript

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

        Attachments

          Activity

            People

            • Assignee:
              hknoechel Hans Knöchel
              Reporter:
              martijnkooij Martijn Kooij
              Reviewer:
              Chee Kiat Ng (Inactive)
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

                • Titanium SDK/CLI <> Titanium Mobile
                  Synced with:
                  TIMOB-20948
                  Sync status:
                  ERROR
                  Last received:
                  Last sent:

                  Git Source Code