Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10172] iOS: Ti.UI.TableView.insertRowBefore does not work after delete a row

GitHub Issuen/a
TypeBug
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 2.1.0, Release 3.1.0
Fix Version/sn/a
ComponentsiOS
Labelsapi, community
Reporterbymer
AssigneeUnknown
Created2012-07-19T09:35:57.000+0000
Updated2018-02-28T20:03:39.000+0000

Description

Problem: ======== Ti.UI.TableView.insertRowBefore does not work after delete a row Reproduction: ============= - insert 2 rows by pressing '+' (list: 2, 1) - swipe first row to delete '2' item (list: 1) - '+' will not work more (insertRowBefore does not work) Sample Code (app.js): ===================== var self = Ti.UI.createWindow({ modal: true }); var tableView = Ti.UI.createTableView({ editable: true}); self.add(tableView); var id = 0; var addButton = Ti.UI.createButton({ systemButton: Ti.UI.iPhone.SystemButton.ADD }); addButton.addEventListener('click', function() { var tableRow = Ti.UI.createTableViewRow({ title: '' + ++id }); tableView.data.length ? tableView.insertRowBefore(0, tableRow) : tableView.appendRow(tableRow); }); self.rightNavButton = addButton; self.open();

Comments

  1. Shameer Jan 2013-04-10

    Issue reproduces Tested with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 Titanium SDK version: 3.0.2 iOS iPhone Simulator: iOS SDK version: 6.0
  2. Kaos Arts 2013-05-27

    Related issue: if you add 3+ rows then delete the first one, next insertRowBefore(0, ...) will add it into the index 1 location instead of index 0. If you delete the first two insertRowBefore(0, ..) will add it to the index 2 location, and so forth. This seems specific to the swipe delete gesture, doesn't repro for programmatic deletions.
  3. Kaos Arts 2013-05-27

    FWIW the same problem exists with insertRowAfter. The bug is related to handling of delete row gestures.
  4. Kaos Arts 2013-05-28

    Patch that works with 3.0.2GA: --- ./aws_example/build/iphone/Classes/TiUITableView.m 2013-03-13 23:04:41.000000000 -0700 +++ ./test/build/iphone/Classes/TiUITableView.m 2013-05-27 17:22:21.000000000 -0700 @@ -1880,26 +1880,27 @@ return result; \ { TiUITableViewSectionProxy *section = [self sectionForIndex:[indexPath section]]; NSInteger index = [self indexForIndexPath:indexPath]; UITableView *table = [self tableView]; NSIndexPath *path = [self indexPathFromInt:index]; // note, trigger action before the update since on the last delete it will be gone.. [self triggerActionForIndexPath:indexPath fromPath:nil tableView:ourTableView wasAccessory:NO search:NO name:@"delete"]; - - [[section rows] removeObjectAtIndex:[indexPath row]]; + + [table beginUpdates]; + TiUITableViewRowProxy* row = [self rowForIndexPath:indexPath]; + [self deleteRow:row]; // If the section is empty, we want to remove it as well. BOOL emptySection = ([[section rows] count] == 0); if (emptySection) { [[(TiUITableViewProxy *)[self proxy] internalSections] removeObjectAtIndex:[indexPath section]]; } - [table beginUpdates]; if (emptySection) { NSIndexSet * thisSectionSet = [NSIndexSet indexSetWithIndex:[indexPath section]]; if([(TiUITableViewProxy *)[self proxy] sectionCount] > 0) { [table deleteSections:thisSectionSet withRowAnimation:UITableViewRowAnimationFade]; } else //There always must be at least one section. So instead, we have it reload to clear out the header and footer, etc.
  5. Thomas Neerup 2015-11-12

    Any chance this will be fixed?... This is still a problem with SDK 5.0

JSON Source