-
-
Save nuno/39a483322e6aa4edef98ac6a7945b767 to your computer and use it in GitHub Desktop.
Cleaning Up Subviews in Appcelerator Titanium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
".container": { | |
backgroundColor:"white" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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