Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16431] iOS/Android: Updating ListItem of ListView displayed after Search crashes app

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionDuplicate
Resolution Date2016-04-27T10:37:14.000+0000
Affected Version/sRelease 3.2.0
Fix Version/sRelease 5.2.0
ComponentsiOS
Labelsandroid, ios, listitem, listview
ReporterYoung
AssigneeChee Kiat Ng
Created2014-01-18T18:03:50.000+0000
Updated2016-04-27T10:37:38.000+0000

Description

App (iOS & Android) crashes when clickHandler of ListView updates ListItem when list being displayed as Search Result. To reproduce the error: 1. add the following code to list_v2_search_searchview.js of Kitchen Sink:
    e.section.updateItemAt(e.itemIndex, {
        properties: { title: 'Will crash app' }
    });
2. do a search (with result) 3. click on any row of the search result (list view) 4. *app crash* Modified Kitchen Sink code:

function clickHandler(e){
    var message = 'Type:'+e.type+'\nSection title:'+e.section.headerTitle+'\nsectionIndex:'+e.sectionIndex+'\nitemIndex:'+e.itemIndex;
    if(isValidVar(e.bindId)){
        message += '\nbindId:'+e.bindId;
    }
    if(isValidVar(e.itemId)){
        message += '\nitemId:'+e.itemId;
    }
    alert(message);

    e.section.updateItemAt(e.itemIndex, {
		properties: { title: 'Will crash app' }
    });
}

Comments

  1. Mostafizur Rahman 2014-01-20

    I tested this issue with the test code below. I can't reproduce this issue. Can you please do a quick test using the code below to see if you can reproduce the error. If so, please let us know.

    Test Environment

    Mac OX S 10.8.5 Ti SDK 3.2.0.GA Ti CLI 3.2.0 IOS simulator 7.0.3

    Test Code

       var win = Ti.UI.createWindow({
       	backgroundColor : 'white',
       	fullscreen : true
       });
       
       var search = Titanium.UI.createSearchBar({
       	barColor : '#000',
       	showCancel : true,
       	height : 43,
       	top : 0,
       });
       search.addEventListener('cancel', function() {
       	search.blur();
       });
       
       var listView = Ti.UI.createListView({
       	searchView : search,
       	caseInsensitiveSearch : true
       });
       
       var listSection = Ti.UI.createListSection();
       var fruits = ['Papaya', 'Peach', 'Pear', 'Persimmon', 'Pineapple', 'Pluot', 'Pomegranate'];
       var data = [];
       for (var i = 0; i < fruits.length; i++) {
       	data.push({
       		properties : {
       			title : fruits[i],
       			searchableText : fruits[i]
       		}
       	});
       }
       listSection.setItems(data);
       
       listView.addEventListener('itemclick', function(e) {
       	e.section.updateItemAt(e.itemIndex, {
       		properties : {
       			title : 'Will crash app'+e.itemIndex
       		}
       	});
       });
       
       listView.sections = [listSection];
       win.add(listView);
       win.open();
       

    Step to Test

    Create a simple project

    Update app.js with my test code

    Run on iOS simulator for testing

    Do a search (with result)

    Click on any row of the search result (list view)

    Test Result

    App is running with out any crash Thanks
  2. Martijn Kooij 2014-02-05

    I am experiencing the same issue. A simple project using Mostafizur Rahman's code also crashes as soon as I click an item in the search results. Code crashes in 3.2.0GA as well as 3.2.1. Ran the project in XCode and the crash occurs in TiUIListview.m, on this line: -(void)buildResultsForSearchText { searchActive = ([searchString length] > 0); >> EXC_BAD_ACCESS I will try to hack fix it, but I hope you can find a real fix soon.
  3. Ritu Agrawal 2014-02-09

    Moving this ticket to engineering as I can reproduce this issue with the following test case on iOS platform. It appears related to TC-3682 (crash with deleteItemsAt) whereas this crash is with updateItemAt.
       var win=Ti.UI.createWindow({
           fullscreen:false
       });
       var template={
           childTemplates:[
               {
                   type:'Ti.UI.Label',
                   bindId:'title'
               }
           ]
       };
       var items=[];
       for(var k=0;k<500;k++){
           items.push({
               properties:{
                       searchableText:'Click to delete '+k
                   },
               title:{text:'Click to delete '+k}
           });
       }
        
       var search=Ti.UI.createSearchBar();
        
       var listView=Ti.UI.createListView({
           templates:{template:template},
           defaultItemTemplate:'template',
           sections:[
                       Ti.UI.createListSection({
                               items:items
                           })
                   ],
           searchView:search
       });
       
       listView.addEventListener('itemclick', function(e) {
           e.section.updateItemAt(e.itemIndex, {
               properties : {
                   title : 'Will crash app'+e.itemIndex
               }
           });
       });
         
       listView.addEventListener('itemclick',function(e){
           var index=e.itemIndex;
           Ti.API.info("Index" + index);
           // e.section.deleteItemsAt(index,1);
           e.section.updateItemAt(e.itemIndex, {
               properties : {
                   title : 'Will crash app' + e.itemIndex
               }
           });
       });
       
       win.add(listView);
       win.open();
       
  4. Hans Knöchel 2016-04-27

    Hey guys, could you try using the latest 5.2.2.GA for this issue? I remember we fixed something related for that release. Thank you! *EDIT*: Using the below code (refactored from above), it does not crash when clicking an item while the search is focussed:
       var win = Ti.UI.createWindow();
       
       var template = {
           childTemplates: [
               {
                   type: 'Ti.UI.Label',
                   bindId: 'title'
               }
           ]
       };
       
       var items = [];
       
       for (var k = 0; k < 500; k++) {
           items.push({
               properties: {
                   searchableText: 'Click to delete ' + k
               },
               title: {
                   text: 'Click to delete ' + k
               }
           });
       }
       
       var search = Ti.UI.createSearchBar();
       var listView = Ti.UI.createListView({
           templates: {
               template: template
           },
           defaultItemTemplate: 'template',
           sections: [
               Ti.UI.createListSection({
                   items: items
               })
           ],
           searchView: search
       });
       
       listView.addEventListener('itemclick', function(e) {
       
           Ti.API.info("Index" + e.itemIndex);
       
           e.section.updateItemAt(e.itemIndex, {
               properties: {
       			searchableText: 'Will crash app' + e.itemIndex
               },
               title: {
                   text: 'Will crash app' + e.itemIndex
               }
           });
       });
       
       win.add(listView);
       win.open();
       
  5. Hans Knöchel 2016-04-27

    Closing for now. If you still experience it, feel free to comment here!

JSON Source