Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-1910] Add a removeAllChildren method to views and windows

GitHub Issuen/a
TypeNew Feature
PriorityTrivial
StatusClosed
ResolutionDuplicate
Resolution Date2013-11-11T17:25:30.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.1.0
ComponentsiOS
Labelsn/a
ReporterRalf Pfeiffer
AssigneeNeeraj Gupta
Created2011-04-15T03:05:21.000+0000
Updated2017-03-20T22:13:29.000+0000

Description

Add the ability to clear all children from a view or a window.

Comments

  1. Stephen Tramer 2012-01-26

    The following is perfectly valid and demonstrates that there is no need for this method:
       var win = Ti.UI.createWindow({
       	backgroundColor:'black'
       });
       for (var i=0; i < 10; i++) {
       	var x = i * 20;
       	for (var j=0; j < 20; j++) {
       		var y = j * 20;
       		var color = 'red';
       		switch ((x+y) % 3) {
       			case 1:
       				color = 'green';
       				break;
       			case 2:
       				color = 'blue';
       				break;
       			default:
       				color = 'red';
       				break;
       		}
       		var view = Ti.UI.createView({
       			left:x,
       			top:y,
       			width:20,
       			height:20,
       			backgroundColor:color
       		});
       		win.add(view);
       	}
       }
       
       var b = Ti.UI.createButton({
       	title:'Clear the view!',
       	width:200,
       	height:40
       });
       win.add(b);
       b.addEventListener('click', function() {
       	var viewChildren = win.children;
       	Ti.API.info(viewChildren);
       	for (var i=0; i < viewChildren.length; i++) {
       		var child = viewChildren[i];
       		win.remove(child);	
       	}
       });
       win.open();
       
    Of course, this is a fairly extreme case... and the upcoming layout API allowing batching of operations should prevent issues like this.
  2. Keith Gable 2012-01-26

    Separate issue then, but view.remove(other_view) does not always work. Also, this would be incredibly inefficient if you had a lot of views to remove (and the platform provided a similar method to remove all child views).
  3. Ivan Skugor 2012-01-27

    Stephen's solution won't work (on Android at least), here is Q/A topic regarding this functionality: http://developer.appcelerator.com/question/131151/emptying-a-view Keith, if "remove" does not work, report it. :) And I agree that this functionality would be useful (along many other :D ).
  4. Neville Dastur 2013-11-09

    Only commenting to say at least with SDK 3.0+ there is now a removeAllChildren() method. This item appears high on a google search for this problem and it has been marked as won't fix. But actually it has been fixed.
  5. Ingo Muschenetz 2013-11-11

    Resolving as duplicate of linked issue.
  6. Lee Morris 2017-03-20

    Closing ticket as duplicate.

JSON Source