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

iOS: listView and listItem index not being updated after delete

    Details

      Description

      Issue

      When working with the listView user delete a listItem from a section trough a button event bound in the template, after the item is deleted the remaining items will keep the original sectionIndex and itemIndex value, if we try to delete elements from the same section we will start receiving Warning about the item not being in range to be deleted and elements will remain on the listView.

      Also after deleting a section the delete function stops working, we also notice the index of the listView remains calling elements from one section in another.

      Steps to repro

      1. Run the test code.
      2. Click Section 0 title:"item 0" label and will be deleted correctly.
      3. Click Section 0 title:"item 1" label and will delete "item 2" as this is located in section 0 item 1 index.
      4. Click Section 0 title:"item 3" label and will throw a warning.
      5. Click Section 1 title:"item 0" label deleting the element and section correctly.
      6. Click Section 2 title:"item 0" label throwing an exception

      Logs

      [WARN] : ListView: Delete item index is out of range

      [UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2903.23/UITableView.m:1330

      Test Case

      index.xml

      <Alloy>
      	<Window title="Win">
      		
              <ListView id="eventsList" class="eventsList" defaultItemTemplate="templateItem">
                  <Templates>
                      <ItemTemplate  id="templateItem" name="templateItem"  class="templateItem">             
      	                <Label id="title" bindId="title" class="title" onClick="doClick"/>
                      </ItemTemplate>
                  </Templates>
                  
                  <ListSection headerTitle="Section 0">
                      <ListItem title:text="Item 0" />
                      <ListItem title:text="Item 1" />
                      <ListItem title:text="Item 2" />
                      <ListItem title:text="Item 3" />
                      <ListItem title:text="Item 4" />
                  </ListSection>
                  <ListSection headerTitle="Section 1">
                      <ListItem title:text="Item 0" />
                  </ListSection>
                  <ListSection headerTitle="Section 2">
                      <ListItem title:text="Item 0" />
                      <ListItem title:text="Item 1" />
                      <ListItem title:text="Item 2" />
                      <ListItem title:text="Item 3" />
                  </ListSection>
                  <ListSection headerTitle="Section 3">
                      <ListItem title:text="Item 0" />
                      <ListItem title:text="Item 1" />
                      <ListItem title:text="Item 2" />
                  </ListSection>
              </ListView>
      		
      	</Window>
      </Alloy>
      

      index.js

       
      function doClick(e){
      	Ti.API.info('Section: '+e.sectionIndex+' ::: Item: '+e.itemIndex);
      	$.eventsList.sections[e.sectionIndex].deleteItemsAt(e.itemIndex,1);
      	if($.eventsList.sections[e.sectionIndex].items.length == 0){
      			$.eventsList.deleteSectionAt(e.sectionIndex);
      		}
      }
       
      $.index.open();
      
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vduggal Vishal Duggal (Inactive)
                Reporter:
                mcota Marco Cota (Inactive)
                Reviewer:
                Sabil Rahim
              • Watchers:
                0 Start watching this issue

                Dates

                • Due:
                  Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Source Code