Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14292] iOS: TableView crashing after clicking on SearchBar-filtered row

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2013-08-02T20:33:40.000+0000
Affected Version/sRelease 3.1.1
Fix Version/s2013 Sprint 16, 2013 Sprint 16 API, Release 3.1.2, Release 3.2.0
ComponentsiOS
Labelsios, qe-testadded, regression, searchbar, tableview
ReporterHani Hamadeh
AssigneeVishal Duggal
Created2013-06-18T10:05:56.000+0000
Updated2013-08-21T10:37:47.000+0000

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

Comments

  1. Daniel Sefton 2013-06-18

    Hi Hani, Before I can escalate this please could you provide a simple reproducible test case which can be dropped into an app.js? Thanks!
  2. Hani Hamadeh 2013-06-18

    You're lucky :P I was able to reproduce it in a simple example. [moved to description]
  3. Daniel Sefton 2013-06-19

    Tested and confirmed on iOS 6 simulator with Ti SDK 3.1.1 GA.
  4. Vishal Duggal 2013-08-02

    Pull pending against master https://github.com/appcelerator/titanium_mobile/pull/4516
  5. Vishal Duggal 2013-08-02

    Backport to 3_1_X https://github.com/appcelerator/titanium_mobile/pull/4536
  6. Lokesh Choudhary 2013-08-15

    Verified the fix & the app does not crash after immediately closing the window when we select the search filtered row. Thus closing. Environment: Appcel Studio : 3.1.2.201308091728 Ti SDK : 3.1.2.v20130814124556 Mac OSX : 10.8.4 Alloy : 1.2.0-beta CLI - 3.1.2-alpha Ipad4 - 6.0.1 Iphone5 - 6.0

JSON Source