Adding Sections + Rows to TableView -- Doc examples don't work?
I'm looking to make a table view and then update it with data. if I put it in the "data" attribute it works, but at the time I initially load the tableView, I might not have the information.
Here's the code:
var search = Titanium.UI.createSearchBar({});
var profilesListWindow = Titanium.UI.createTableView({
search: search,
filterAttribute: "title",
width: "65%",
height: "80%",
borderRadius: 20
});
backgroundSkin.add(profilesListWindow);
var section = Titanium.UI.createTableViewSection();
section.headerTitle = "Hello";
var row1 = Titanium.UI.createTableViewRow({title:"Hello 1"});
var row2 = Titanium.UI.createTableViewRow({title:"Hello 2"});
section.add(row1);
section.add(row2);
profilesListWindow.add(section);
The last section is taken directly from the documentation and looks valid. It gives no errors, the tableView just doesn't show. I've tried moving when I show the table as well, thinking it was an ordering thing, and that didn't have any effect.
Thoughts on why this seemingly simple process won't work?
2 Answers
-
Hey Nathan,
You'll want to use the setData method if you want to add data to a tableView after it's been created. Try something like this:
var search = Titanium.UI.createSearchBar({}); var profilesListWindow = Titanium.UI.createTableView({ search: search, filterAttribute: "title", width: "65%", height: "80%", borderRadius: 20 }); backgroundSkin.add(profilesListWindow); var data = []; var section = Titanium.UI.createTableViewSection(); section.headerTitle = "Hello"; var row1 = Titanium.UI.createTableViewRow({title:"Hello 1"}); var row2 = Titanium.UI.createTableViewRow({title:"Hello 2"}); section.add(row1); section.add(row2); data.push(section); profilesListWindow.setData(data);
-
Hello,
Try by changing this line:
profilesListWindow.add(section);
For this other line:
profilesListWindow.appendSection(section);
It should work.
If not, keeping my firt suggestion, add this at the end of your code to refresh you table:
var temp = $.profilesListWindow.data; $.profilesListWindow.setData(temp);
I hope it helps.
J. Pablo.