Skip to content

Instantly share code, notes, and snippets.

@mauropm
Created December 14, 2011 21:54
Show Gist options
  • Save mauropm/1478739 to your computer and use it in GitHub Desktop.
Save mauropm/1478739 to your computer and use it in GitHub Desktop.
Example NS and dynamic creation of views
tt.ui.createStackView = function(_args) {
var stack = Ti.UI.createView(tt.combine($$.stretch,_args.props||{}));
stack.currentIndex = _args.currentIndex||0;
//populate stack
for (var i = 0; i < _args.views.length; i++) {
var w = _args.views[i];
if (i == stack.currentIndex) {
w.visible = true;
}
else {
w.visible = false;
}
stack.add(w);
}
stack.addEventListener('changeIndex', function(e) {
for (var j = 0;j < _args.views.length;j++) {
if (j == e.idx) {
_args.views[j].visible = true;
stack.currentIndex = j;
}
else {
_args.views[j].visible = false;
}
}
});
return stack;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment