-
-
Save artanisdesign/2868242 to your computer and use it in GitHub Desktop.
How to append a row to particular section in 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
(function() { | |
var win = Ti.UI.createWindow(); | |
var section1 = Ti.UI.createTableViewSection({ | |
headerTitle:'Header 1' | |
}); | |
for (var i=0; i < 4; i++) { | |
section1.add(Ti.UI.createTableViewRow({ | |
title:'Row '+i | |
})); | |
} | |
var section2 = Ti.UI.createTableViewSection({ | |
headerTitle:'Header 2' | |
}); | |
for (i=4; i < 10; i++) { | |
section2.add(Ti.UI.createTableViewRow({ | |
title:'Row '+i | |
})); | |
} | |
var tv = Ti.UI.createTableView({ | |
data:[section1,section2] | |
}); | |
function appendRowToSection(tableView, row, sectionIndex) { | |
var sections = tableView.data; | |
if (!sections || sections.length < sectionIndex || isNaN(+sectionIndex)) { | |
return; | |
} | |
sections[sectionIndex].add(row); | |
tableView.setData(sections); | |
} | |
win.add(tv); | |
tv.addEventListener("click", function() { | |
appendRowToSection(tv, Ti.UI.createTableViewRow({ title: "new row"}), 0); | |
}); | |
win.open(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment