Skip to content

Instantly share code, notes, and snippets.

@grantges
Created February 12, 2016 15:03
Show Gist options
  • Save grantges/884ae6b2fd8570a89109 to your computer and use it in GitHub Desktop.
Save grantges/884ae6b2fd8570a89109 to your computer and use it in GitHub Desktop.
Cleaning Up Subviews in Appcelerator Titanium
$.index.open();
var subViews = [];
function _doSomething(){
alert('Something!');
}
function createCleanUpViews(){
for(i=0;i<10;i++){
var view = Ti.UI.createView({
backgroundColor:"red",
height:50,
borderColor: 'black',
borderWidth: 1,
width: Ti.UI.FILL});
view.addEventListener('click', _doSomething);
subViews.push(view);
$.scrollView.add(view);
}
setTimeout(function(){
$.scrollView.removeAllChildren();
console.log(subViews.length);
cleanUpSubViews();
console.log(subViews.length);
setTimeout(createCleanUpViews, 1000)
}, 5000);
}
function cleanUpSubViews(){
while(subViews.length) {
var v = subViews.pop();
v.removeEventListener('nowHearThis', _doSomething);
v = null;
};
}
createCleanUpViews();
".container": {
backgroundColor:"white"
}
<Alloy>
<Window class="container">
<ScrollView id="scrollView" backgroundColor='#ececec' layout="vertical" height="Ti.UI.FILL" width="Ti.UI.FILL" />
</Window>
</Alloy>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment