TableViewSection on Android crashes app
I'm trying to use TableViewSections according to the example on the API page:
somearray[key] = Ti.UI.createTableViewSection();
somearray[key].headerTitle = 'blah blah';
somearray[key].add( mytableviewrow );
mytableview.add( somearray[key] );
The app crashes (in the emulator) upon mytableview.add().
3 Answers
-
The problem appears to be caused by the undocumented fact that
myTableView.add(myTableViewSection);
doesn't work as expected. Rather, you have to add the sections to the data array and then set the tableView's .data property later.Here is an example:
var songListingTable = Titanium.UI.createTableView(); var data = new Array(); for(albumIndex in window.data.albums){ var album = window.data.albums[albumIndex]; var tableSection = Ti.UI.createTableViewSection({}); tableSection.headerTitle = albumName; for(songIndex in album.songs){ var song = album.songs[songIndex]; var songRow = Ti.UI.createTableViewRow({title: song}); tableSection.add(songRow); } // Add the section here. Will set data value of table later. data.push(tableSection); } songListingTable.data = data;
PS: This seems to be the same problem as http://developer.appcelerator.com/question/74621/tableviewsection-not-creating-sections
-
This may sound dumb, but how do you "Set your Log Level to Trace" … I've been searching up/down/Google for this with no avail.
-
it's actually inside the Ti Developer, right next to the dropdown for the SDK, you can choose another dropdown for trace, debug, info, etc.
rocksteady,
danno~