Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14166] iOS: Delete section that include focused textfield causes app to crash

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-03-31T17:35:56.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.0.0
Componentsn/a
LabelsTSP, deleteSection, tableview, textfield
ReporterCarter Lathrop
AssigneePedro Enrique
Created2013-06-10T09:00:31.000+0000
Updated2015-04-09T21:08:08.000+0000

Description

If I want to delete section using "table.deleteSection(index, animate);" and I want to delete all sections application unfortunately crash. *Application crash only if I before clicked on a textfield ,so textfield has focus. *EXAMPLE:*
 
var win = Ti.UI.createWindow({layout: "vertical"});
var table = Ti.UI.createTableView({ style: Ti.UI.iPhone.TableViewStyle.GROUPED });
var data = [];

var buttonsWrap  = Ti.UI.createView({layout: "horizontal", width: Ti.UI.FILL, height: Ti.UI.SIZE});
var removeFromBottom = Ti.UI.createButton({title: "REMOVE FROM BOTTOM", width: "50%", height: 30});
	removeFromTop = Ti.UI.createButton({title: "REMOVE FROM TOP", width: "50%", height: 30});

for(i=0;i<3;i++)
{
	var section = Ti.UI.createTableViewSection({width: Ti.UI.FILL, height: Ti.UI.SIZE});
	var row = Ti.UI.createTableViewRow({width: Ti.UI.FILL, height: Ti.UI.FILL, backgroundImage: "transparentBG.png"});
	var tField = Ti.UI.createTextField({width: Ti.UI.FILL, height: Ti.UI.FILL, backgroundColor: "white"});
	
	row.add(tField);
	section.add(row);
	data.push(section);
}


table.data = data;

buttonsWrap.add(removeFromBottom);
buttonsWrap.add(removeFromTop);

win.add(buttonsWrap);
win.add(table);
win.open();


removeFromBottom.addEventListener("click", function(){
	table.deleteSection(2, {animationStyle: Ti.UI.iPhone.RowAnimationStyle.FADE});
	table.deleteSection(1, {animationStyle: Ti.UI.iPhone.RowAnimationStyle.FADE});		
	table.deleteSection(0, {animationStyle: Ti.UI.iPhone.RowAnimationStyle.FADE});					
});

removeFromTop.addEventListener("click", function(){
	table.deleteSection(0, {animationStyle: Ti.UI.iPhone.RowAnimationStyle.FADE});	
	table.deleteSection(0, {animationStyle: Ti.UI.iPhone.RowAnimationStyle.FADE});	
	table.deleteSection(0, {animationStyle: Ti.UI.iPhone.RowAnimationStyle.FADE});			
});
*CONSOLE OUTPUT:* {quote} [ERROR] : The application has crashed with an uncaught exception 'NSInternalInconsistencyException'. [ERROR] : Reason: [ERROR] : request for rect of invalid section (-1) [ERROR] : Stack trace: [ERROR] : 0 CoreFoundation 0x038ed012 __exceptionPreprocess + 178 [ERROR] : 1 libobjc.A.dylib 0x033aee7e objc_exception_throw + 44 [ERROR] : 2 CoreFoundation 0x038ece78 +[NSException raise:format:arguments:] + 136 [ERROR] : 3 Foundation 0x00e63665 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 [ERROR] : 4 UIKit 0x013933e3 -[UITableViewRowData rectForSection:] + 181 [ERROR] : 5 UIKit 0x01257144 -[UITableView rectForSection:] + 80 [ERROR] : 6 ewd 0x000cd16e -[TiUITableView keyboardDidShowAtHeight:] + 430 [ERROR] : 7 ewd 0x001f6425 -[TiRootViewController handleNewKeyboardStatus] + 869 [ERROR] : 8 Foundation 0x00dcb5b3 __NSFireDelayedPerform + 380 [ERROR] : 9 CoreFoundation 0x038ac376 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22 [ERROR] : 10 CoreFoundation 0x038abe06 __CFRunLoopDoTimer + 534 [ERROR] : 11 CoreFoundation 0x03893a82 __CFRunLoopRun + 1810 [ERROR] : 12 CoreFoundation 0x03892f44 CFRunLoopRunSpecific + 276 [ERROR] : 13 CoreFoundation 0x03892e1b CFRunLoopRunInMode + 123 [ERROR] : 14 GraphicsServices 0x036747e3 GSEventRunModal + 88 [ERROR] : 15 GraphicsServices 0x03674668 GSEventRun + 104 [ERROR] : 16 UIKit 0x011aaffc UIApplicationMain + 1211 [ERROR] : 17 ewd 0x00004358 main + 456 [ERROR] : 18 ewd 0x00002c65 start + 53 [ERROR] : 2013-06-10 09:49:24.010 ewd[42008:1c103] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect of invalid section (-1)' [ERROR] : *** First throw call stack: [ERROR] : (0x38ed012 0x33aee7e 0x38ece78 0xe63665 0x13933e3 0x1257144 0xcd16e 0x1f6425 0xdcb5b3 0x38ac376 0x38abe06 0x3893a82 0x3892f44 0x3892e1b 0x36747e3 0x3674668 0x11aaffc 0x4358 0x2c65) -- End simulator log --------------------------------------------------------- [INFO] : Application has exited from iOS Simulator [INFO] : Project built successfully in 31s 418ms {quote} *WORKAROUND* {quote} Just call for every textfield function blur(); {quote}

Comments

  1. Carter Lathrop 2013-06-10

    Confirmed with 3.2CI, iOS sim 6.0, with Titanium Studio, build: 3.1.0.201303032333. Thanks for bringing this to our attention. Moving to Ti-Mobile. Regards, Carter
  2. Pedro Enrique 2015-03-27

    [~egomez] confirming that there is a bug in TableView. The reason this is happening is that the TextFields have a height of "Ti.UI.SIZE" and the system is calculating a float value height of 49.6666 when you type something and then rounding that to 49.0. On editing the text by typing more, it goes back to 49.6666 and then it compares it to the previos 49.0. This tells the TableView to do an update on the rows, the sections, and so on. For some reason, still investigating, this is causing the internal TableView to fail a assert statement on the number or sections. To work around this, for now, hard code the height of the TextField to something appropriate, such as "44", or "50". Setting the height of the TextField will avoid all the automatic checks and unnecessary updates on the TableView data source. Solution: use a number for the height of the TextField instead of Ti.UI.SIZE
  3. Vishal Duggal 2015-03-31

    This issue is the same as the one related in TIMOB-17404 and is already fixed in 4_0_X and master branches
  4. Lokesh Choudhary 2015-04-09

    Verified the fix. Deleting the section that includes a focussed textfield does not crash the app. Closing. Environment: Appc Studio : 4.0.0.201504081125 Ti SDK : 4.0.0.v20150408131013 CLI : 4.0.0-beta5 Alloy : 1.6.0-beta2 MAC Yosemite : 10.10.2 Appc npm : 0.3.39 Appc CLI : 0.2.235

JSON Source