Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created August 18, 2011 06:11
Show Gist options
  • Select an option

  • Save aaronksaunders/1153438 to your computer and use it in GitHub Desktop.

Select an option

Save aaronksaunders/1153438 to your computer and use it in GitHub Desktop.
Group table view sections by table data?
// this sets the background color of the master UIView (when there are no windows/tab groups on it)
Titanium.UI.setBackgroundColor('#000');
// create tab group
var tabGroup = Titanium.UI.createTabGroup();
//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff',
tabBarHidden : true
});
var tab1 = Titanium.UI.createTab({
icon : 'KS_nav_views.png',
title : 'Tab 1',
window : win1
});
var data = {
"north" : ["north 1", "north 2", "north 3"],
"east" : ["east 1", "east 2", "east 3"],
"south" : ["south 1", "south 2", "south 3"],
"west" : ["west 1", "west 2", "west 3"]
};
// create table view
var tableView1 = Titanium.UI.createTableView({
data : [],
rowHeight : 'auto'
});
var rows = [];
for(var headerString in data ) {
Ti.API.debug(headerString);
for(var i = 0; i < data[headerString].length; i++) {
Ti.API.debug(data[headerString][i]);
var row = Ti.UI.createTableViewRow({
title : data[headerString][i]
});
if(i === 0) {
row.header = headerString;
}
rows.push(row);
};
}
tableView1.setData(rows);
win1.add(tableView1);
// add tabs
//
tabGroup.addTab(tab1);
// open tab group
tabGroup.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment