Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Persistent Window?

I have a TableView menu for my application; one of the options is to write a note. Here is the invocation code:

winNote = Titanium.UI.createWindow({
    url:'../application_windows/notes.js',
    title:'Notes'
});

rowNote.addEventListener('click', function(e)
{
    Titanium.UI.currentTab.open(winNote,{animated:true});
});

Pretty simple, straight forward, and works; but the notes window does not remain persistent. That is, if I click back on the top toolbar (iOS4 emulator), it goes back, and if I click the Notes row on the TableViewRow, it resets the content of the text area as if it is a new window.

Is there any special procedures I need to do in order to ensure the notes are persistent?

— asked November 23rd 2010 by Andy Huang
  • iphone
  • mobile
  • persistent
  • tableviewrow
  • window
0 Comments

3 Answers

  • Accepted Answer

    As far as I've seen Kitchen sink doesnt persist data after you've closed the page either.

    I think what you want to do is store the data so you can get to it later. Try something like this:

    //You'll have to pass in the clicked id some how.. perhaps store it as an
    //app property and access it like this:
    var winNoteProps = JSON.parse(Ti.App.Properties.getString("winNoteProps"));
    
    //get the data from a local database
    var db = Titanium.Database.open('mylocaldb');
    var rows = db.execute('Select Notes from NotesTable where winNoteId = ' + winNoteProps.id);
    db.close();
    
    var notes = rows.fieldByName('Notes');
    
    taNotes.value = notes;
    
    
    //add an event listener to trigger the database save
    taNotes.addEventListener('blur', function(e){
      var db = Titanium.Databse.open('mylocaldb');
      db.execute('INSERT INTO NOTESTABLE (Notes, winNoteId) VALUES (?,?)',
        e.value, winNoteProps.id);
      db.close();
    }
    

    With this solution you'll have to setup the above database and tables before you use them. The best place is probably in the app.js file.

    Check out this article for some more detailed look at database use and this guide for passing the variables between pages as application properties.

    Hope this helps.

    — answered November 27th 2010 by Jonathon Beschen
    permalink
    0 Comments
  • can you post the code from notes.js?

    I am going to guess that you are doing something that is cause you to lose the context and the data that was added when the window was opened

    — answered November 23rd 2010 by Aaron Saunders
    permalink
    1 Comment
    • Hi, thanks for replying…
      Here's the code for notes.js:

      var win = Titanium.UI.currentWindow;
      
      taNotes = Titanium.UI.createTextArea({
          value:'I am a textarea',
          height:400,
          width:320,
          top:0,
          font:{fontSize:20,fontFamily:'Helvatica', fontWeight:'bold'},
          color:'#000',
          textAlign:'left',
          appearance:Titanium.UI.KEYBOARD_APPEARANCE_ALERT,    
          keyboardType:Titanium.UI.KEYBOARD_NUMBERS_PUNCTUATION,
          returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
          suppressReturn:false
      
      });
      win.add(taNotes);
      

      It is mostly copy and pasted from the kitchen sink, except much trimmed down… I tried to change "I am a textarea" to "I am a text-area" as recommended by the auto-correct, as well as typing random asdf qwerty etc. type of dummy text into the text area, but as soon as I click back, and come back, it reverts to "I am a textarea".

      — commented November 23rd 2010 by Andy Huang
  • Bumpty bumpty… Does anyone have any insights on this?

    — answered November 26th 2010 by Andy Huang
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.