I'm totally new and I really need some help. I've googled and searched the Q&A here and I havent found anything that I can apply to my problem.
When i press the edit button and move around my rows I would like to save what I moved or deleted if I terminate the app. I was thinking of giving my rows a value from the loop and then try to save those values in the edited order within the done button. If that is possible? A hint would be fantastic. :)
Titanium.UI.setBackgroundColor('#000'); var tabGroup = Titanium.UI.createTabGroup(); var win = Titanium.UI.createWindow({ title:"Main", backgroundColor:"#fff", tabBarHidden:true }); var button = Ti.UI.createButton({ title: "edit", }); win.setRightNavButton(button); var tab = Titanium.UI.createTab({ title:"Tab1", window:win }); var data = [ {title:"Rad1", className:"tableRow"}, {title:"Rad2", className:"tableRow"}, {title:"Rad3", className:"tableRow"}, {title:"Rad4", className:"tableRow"}, {title:"Rad5", className:"tableRow"}, {title:"Rad6", className:"tableRow"} ] var rowData = []; for(var i = 0; i < data.length; i++){ var row = Titanium.UI.createTableViewRow({ title:data[i].title, className:data[i].className, hasChild:true }); rowData.push(row); } var tableView = Titanium.UI.createTableView({ data:rowData, editable:true, allowsSelectionDuringEditing:true, moving:false }); tableView.addEventListener("click", function(e){ var w = Titanium.UI.createWindow({ title:e.rowData.title, backgroundColor:"#fff" }); var label = Titanium.UI.createLabel({ text:"this is a new window", height:"auto", width:"auto" }) w.add(label); tab.open(w,{animated:true}); }); button.addEventListener('click', function(e) { if (!tableView.moving){ tableView.moving = true; e.source.title = "done"; } else { tableView.moving = false; e.source.title = "edit"; } }); win.add(tableView); tabGroup.addTab(tab); tabGroup.open();
1 Answer
Accepted Answer
A simple solution to achieve that is storing your row data of your Tableview ("tableView.data[0].rows") permanently with Ti.App.Properties...
Here's the code:
Titanium.UI.setBackgroundColor('#000'); var tabGroup = Titanium.UI.createTabGroup(); var win = Titanium.UI.createWindow({ title:"Main", backgroundColor:"#fff", tabBarHidden:true }); var button = Ti.UI.createButton({ title: "edit", }); win.setRightNavButton(button); var tab = Titanium.UI.createTab({ title:"Tab1", window:win }); var data = [ {title:"Rad1", className:"tableRow"}, {title:"Rad2", className:"tableRow"}, {title:"Rad3", className:"tableRow"}, {title:"Rad4", className:"tableRow"}, {title:"Rad5", className:"tableRow"}, {title:"Rad6", className:"tableRow"} ]; var rowData = JSON.parse(Ti.App.Properties.getString("rowData")); Ti.API.info("rowData: "+rowData); if (!rowData) { rowData = []; for(var i = 0; i < data.length; i++){ var row = Titanium.UI.createTableViewRow({ title:data[i].title, className:data[i].className, hasChild:true }); rowData.push(row); } } var tableView = Titanium.UI.createTableView({ data:rowData, editable:true, allowsSelectionDuringEditing:true, moving:false }); tableView.addEventListener("click", function(e){ var w = Titanium.UI.createWindow({ title:e.rowData.title, backgroundColor:"#fff" }); var label = Titanium.UI.createLabel({ text:"this is a new window", height:"auto", width:"auto" }) w.add(label); tab.open(w,{animated:true}); }); button.addEventListener('click', function(e) { if (!tableView.moving){ tableView.moving = true; e.source.title = "done"; } else { tableView.moving = false; Ti.App.Properties.setString("rowData", JSON.stringify(tableView.data[0].rows)); e.source.title = "edit"; } }); win.add(tableView); tabGroup.addTab(tab); tabGroup.open();
Your Answer
Think you can help? Login to answer this question!