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

iOS: TableView crashing after clicking on SearchBar-filtered row

    Details

      Description

      Problem
      The iPhone version of my app is crashing. This happens with Ti 3.1.0 but not with 3.0.2. The view consists of a window containing a table view and a search bar. when the window opens a request is sent to the server and data is retrieved to populate the tableview. When any row is clicked the window closes and the value of the row is returned. The crash happens when I click on any row resulting from search bar filtering.

      Test case

      var win1 = Ti.UI.createWindow({
      	backgroundColor : "#FFF"
      });
       
      var wins = Ti.UI.createWindow({
      	backgroundColor : 'white'
      });
       
      var nav = Titanium.UI.iPhone.createNavigationGroup({
      	window : wins
      });
       
      var btn = Ti.UI.createButton({
      	title : 'click'
      });
       
      btn.addEventListener('click', function(e) {
      	var win = Titanium.UI.createWindow({
      		backgroundColor : 'white'
      	});
      	var search = Titanium.UI.createSearchBar({
      		showCancel : true,
      		height : 43,
      		top : 0
      	});
      	var data = [];
       
      	data[0] = Titanium.UI.createTableViewSection({
      		headerTitle : 'Header 1'
      	});
      	data[0].add(Titanium.UI.createTableViewRow({
      		title : 'Row 1'
      	}));
       
      	data[1] = Titanium.UI.createTableViewSection({
      		headerTitle : 'Header 2'
      	});
      	data[1].add(Titanium.UI.createTableViewRow({
      		title : 'Row 2'
      	}));
       
      	search.addEventListener('focus', function(e) {
      		Ti.API.info('focus');
      	});
       
      	var tableview = Titanium.UI.createTableView({
      		data : data,
      		search : search,
       
      	});
       
      	tableview.addEventListener('click', function(e) {
      		Ti.API.info(e);
      		nav.close(win);
      	});
       
      	win.add(tableview);
       
      	nav.open(win);
      });
       
      wins.add(btn);
       
      win1.add(nav);
      win1.open();
      

      Log

      [ERROR] :  The application has crashed with an uncaught exception 'NSInternalInconsistencyException'.
      [ERROR] :  Reason:
      [ERROR] :  attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update
      [ERROR] :  Stack trace:
      [ERROR] :  0   CoreFoundation                      0x038d3012 __exceptionPreprocess + 178
      [ERROR] :  1   libobjc.A.dylib                     0x03394e7e objc_exception_throw + 44
      [ERROR] :  2   CoreFoundation                      0x038d2e78 +[NSException raise:format:arguments:] + 136
      [ERROR] :  3   Foundation                          0x00e6af35 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
      [ERROR] :  4   UIKit                               0x01250ec7 -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 6056
      [ERROR] :  5   UIKit                               0x0125f846 -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 337
      [ERROR] :  6   UIKit                               0x0125f908 -[UITableView reloadRowsAtIndexPaths:withRowAnimation:] + 66
      [ERROR] :  7   Orderoso                            0x000c3f15 -[TiUITableView hideSearchScreen:] + 661
      [ERROR] :  8   Foundation                          0x00dd2e83 __NSFireDelayedPerform + 380
      [ERROR] :  9   CoreFoundation                      0x03892376 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
      [ERROR] :  10  CoreFoundation                      0x03891e06 __CFRunLoopDoTimer + 534
      [ERROR] :  11  CoreFoundation                      0x03879a82 __CFRunLoopRun + 1810
      [ERROR] :  12  CoreFoundation                      0x03878f44 CFRunLoopRunSpecific + 276
      [ERROR] :  13  CoreFoundation                      0x03878e1b CFRunLoopRunInMode + 123
      [ERROR] :  14  GraphicsServices                    0x0365a7e3 GSEventRunModal + 88
      [ERROR] :  15  GraphicsServices                    0x0365a668 GSEventRun + 104
      [ERROR] :  16  UIKit                               0x011b165c UIApplicationMain + 1211
      [ERROR] :  17  Orderoso                            0x00004198 main + 456
      [ERROR] :  18  Orderoso                            0x00002ac5 start + 53
      [ERROR] :  2013-06-12 23:15:44.835 Orderoso[6411:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'
      [ERROR] :  *** First throw call stack:
      [ERROR] :  (0x38d3012 0x3394e7e 0x38d2e78 0xe6af35 0x1250ec7 0x125f846 0x125f908 0xc3f15 0xdd2e83 0x3892376 0x3891e06 0x3879a82 0x3878f44 0x3878e1b 0x365a7e3 0x365a668 0x11b165c 0x4198 0x2ac5)
      

      I found the cause of crash. it is this line in TiUITableView.m which delays hiding the search bar for 200 ms, when I am closing the window immediately.

      [self performSelector:@selector(hideSearchScreen:) withObject:nil afterDelay:0.2];
      

      Workaround
      Delay closing the window.

      Please check the comment at: https://github.com/appcelerator/titanium_mobile/commit/594bee84c41b352996d6dcf7a304f1e9ae32af67#commitcomment-3446266

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                vduggal Vishal Duggal (Inactive)
                Reporter:
                hini Hani Hamadeh
                Reviewer:
                Sabil Rahim
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

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

                    Git Integration