Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17426] iOS: ListView - a lot of items, changes others like clones

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2014-09-08T21:45:17.000+0000
Affected Version/sRelease 3.2.3, Release 3.3.0
Fix Version/sn/a
ComponentsiOS
LabelsTCSupport, android, cloned, ios, iphone, items, listview
ReporterTobias Høegh
AssigneeIngo Muschenetz
Created2014-07-17T11:05:46.000+0000
Updated2017-03-24T17:13:18.000+0000

Description

Problem Description

If you change an item, the change will be reflected on other items as well by error.

Steps to reproduce

1. Create a new mobile app (classic titanium) 2. Paste the testcode into the app.js
var win = Ti.UI.createWindow();

var myTemplate = {
	properties: {
		height: 50,
		accessoryType: Ti.UI.LIST_ACCESSORY_TYPE_NONE,
		selectionStyle: Ti.UI.iPhone.ListViewCellSelectionStyle.NONE,
	},
	childTemplates: [
		{
			type:'Ti.UI.View',
			bindId:'bindField',
			properties: {
				width:Ti.UI.FILL,
				backgroundColor: 'green',
			},
		},
	],
					
	events: {
		'click': function(e){
			// Ti.API.log(e);
			e.source.backgroundColor = e.source.backgroundColor=='green'?'red':'green';
		},
	},
	
};

var itemCount = 100;// Change this to 10 and the bug won't happen
var section = Ti.UI.createListSection();
var data = [], views;
for (var i=0;i<itemCount;++i){
	data.push({
		template: 'myCell',
		properties: {
			itemId: 'id'+i,
		},
		bindField:{
		},
	});
}
section.setItems(data);

var listView = Ti.UI.createListView({
	top: 20,
	templates:{'myCell':myTemplate},
	sections:[section],
	// separatorStyle: Ti.UI.iPhone.ListViewSeparatorStyle.NONE,
	separatorInsets: {left:0, right:0},
});

win.add(listView);
win.open();
3. Run the app and click on the second item. 4. Scroll down and you will see that the second row of the next "page/screen" changed as well (like if they were clones) Extra info: If I set down itemCount = 10; then this behavior will not happen. - Other examples here: http://developer.appcelerator.com/question/176217/did-someone-have-seen-this

Attachments

FileDateSize
Skjermbilde 2014-07-17 kl. 13.03.11.png2014-07-17T11:05:46.000+000031975
Skjermbilde 2014-07-17 kl. 13.05.19.png2014-07-17T11:05:46.000+000028918

Comments

  1. Mauro Parra-Miranda 2014-07-30

    Thanks for your report! Your testcase helped a lot to reproduce the issue! The Platform team will set the priority on this bug.
  2. Shameer Jan 2014-08-14

    Issue reproduces Titanium Command-Line Interface, CLI version 3.3.0, Titanium SDK version 3.3.0.GA iOS SDK: 7.1 iOS iPhone Simulator: 7.1
  3. Vishal Duggal 2014-09-08

    This line is the problem
       e.source.backgroundColor = e.source.backgroundColor=='green'?'red':'green';
       
    ListView is a data based API system, not a View based API system. So when you modify a view directly and not the data, we have no way to know. So when a cell gets reused we do not reset the property. You should be modifying the item instead.
  4. Tobias Høegh 2014-09-09

    Thanks [~vduggal]. Sounds logical. For all who came over the same issue, this code is the way to go:
           events: {
               'click': function(e){
                   var item = e.section.getItemAt(e.itemIndex);
                   item.bindField.backgroundColor = item.bindField.backgroundColor == 'green'?'red':'green';
                   e.section.updateItemAt(e.itemIndex, item), item = null;
               },
           },
       
  5. Lee Morris 2017-03-24

    Closing ticket as invalid with reference to the above comments.

JSON Source