Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-15692] TiAPI: removeAllChildren method for view

GitHub Issuen/a
TypeNew Feature
Priorityn/a
StatusClosed
ResolutionFixed
Resolution Date2012-09-21T13:46:15.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.1.0
ComponentsAndroid, iOS
Labelsandroid, ios, module_views, qe-closed-3.2.0, qe-testadded, remove, view
ReporterMartin Guillon
AssigneeSabil Rahim
Created2012-08-21T00:46:39.000+0000
Updated2014-01-23T10:38:25.000+0000

Description

It can be very useful to have a safe method to remove all children from a view. test case
var win = Ti.UI.createWindow({ backgroundColor: '#fff' });
var scrollView = Ti.UI.createScrollView({height:200,top:0});
win.add(scrollView);

var view1 = Ti.UI.createView({
	backgroundColor:'pink',
	zIndex:10,
	width:200,
	height:30,
	top:10,
	left:10
});

var view2 = Ti.UI.createView({
	backgroundColor:'blue',
	zIndex:11,
	width:200,
	height:30,
	top:15,
	left:15
});

var view3 = Ti.UI.createView({
	backgroundColor:'red',
	zIndex:12,
	width:200,
	height:30,
	top:20,
	left:20
});

scrollView.add(view3);
scrollView.add(view2);
scrollView.add(view1);

var l = Ti.UI.createLabel({
	text:'scroll view: red on top, blue in the middle, pink below',
	color:'#777',
	width:300,
	height:20,
	top:50,
	left:10,
	font:{fontSize:12}
});
scrollView.add(l);

var buttonAdd = Ti.UI.createButton({
	title: 'Add',
	top: 10,
	width: 200,
	height: 30
});

buttonAdd.addEventListener('click', function(){
	scrollView.add(view3);
	scrollView.add(view2);
	scrollView.add(view1);
	scrollView.add(l);
});
win.add(buttonAdd);

var buttonRemove = Ti.UI.createButton({
	title: 'RemoveAll',
	bottom: 10,
	width: 200,
	height: 30
});

buttonRemove.addEventListener('click', function(){
	scrollView.removeAllChildren();
});
win.add(buttonRemove);
win.open();

Comments

  1. Martin Guillon 2012-08-21

    pull request https://github.com/appcelerator/titanium_mobile/pull/2788
  2. Anirudh Nagesh 2012-09-05

    Pull request needs to be merged
  3. Anirudh Nagesh 2012-09-21

    PR submitted
  4. Sabil Rahim 2012-11-02

  5. Priya Agarwal 2014-01-06

    removeAllChildren method working fine... Hence verified and closed. Appc-Studio: 3.2.0.201312191455 Sdk:3.2.0.GA acs:1.0.11 alloy:1.3.1-beta npm:1.3.2 titanium:3.2.0 titanium-code-processor:1.1.0 Osx: Maverick 10.9 Xcode: xCode 5.0.2 Device: HTC Desire(v4.0.3) and iPHONE Simulator(v7.0.3)

JSON Source