[TIMOB-1910] Add a removeAllChildren method to views and windows
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Trivial |
Status | Closed |
Resolution | Duplicate |
Resolution Date | 2013-11-11T17:25:30.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 3.1.0 |
Components | iOS |
Labels | n/a |
Reporter | Ralf Pfeiffer |
Assignee | Neeraj Gupta |
Created | 2011-04-15T03:05:21.000+0000 |
Updated | 2017-03-20T22:13:29.000+0000 |
Description
Add the ability to clear all children from a view or a window.Comments
- Stephen Tramer 2012-01-26
The following is perfectly valid and demonstrates that there is no need for this method:
Of course, this is a fairly extreme case... and the upcoming layout API allowing batching of operations should prevent issues like this.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();
- 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).
- 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 ).
- 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.
- Ingo Muschenetz 2013-11-11 Resolving as duplicate of linked issue.
- Lee Morris 2017-03-20 Closing ticket as duplicate.