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

iOS: Editable TableView loses correct index when using swipe-delete gesture then .deleteRow()

    Details

      Description

      The following tableview displays 20 numbered rows. The tableview is set as "editable:true", so the swipe-to-delete gesture is enabled in iOS. The tableview also has a click event handler, so any row clicked on, will be deleted as well with the TableView.deleteRow() method. The idea is that a user can swipe-to-delete any row, or simply click any row to delete it.

      Problem: Swipe-deleting a row, then calling .deleteRow() on a later row causes the display to remove the incorrect row. Seems like Swipe-to-delete is causing an indexing problem with the rows.

      For example;

      1. Load the app.

      2. Click on "Row 1" to delete it. This works fine.

      3. Swipe-to-delete "Row 2" and delete it. This works fine.

      3. Click on "Row 3" to delete it. This fails, and "Row 4" gets deleted instead of "Row 3".

      Anytime you swipe-delete a row, any other rows below that one which are deleted with TableView.deleteRow() miss the correct index, instead deleting something farther below their index.

      The more swipe-deletes you do, the more the index is offset incorrectly when calling .deleteRow().

      Using $.tv.deleteRow(e.index) or $.tv.deleteRow(e.row) does not make a difference.

      Here's the code:

      index.xml:

      <Alloy>
        <NavigationWindow>
          <Window>
            <TableView id="tv" editable="true" onClick="tv_onClick">	
            </TableView>
          </Window>
        </NavigationWindow>
      </Alloy>	
      

      index.js:

      var tableData = [];
       
      for (var i=1; i<21; i++) {
        tableData.push({ title: 'Row ' + i });
      }
       
      $.tv.setData(tableData);
      $.index.open();
       
      function tv_onClick(e) {	
        $.tv.deleteRow(e.index);
      }
      

        Attachments

          Activity

            People

            • Assignee:
              srahim Sabil Rahim
              Reporter:
              ewieber Eric Wieber
            • Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Backbone Issue Sync

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

                  Git Source Code