Titanium Community Questions & Answer Archive

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

How to preload for Windows in tabs

Hi,

I need to preload all the windows in the tabgroup. I read on this forum that createWindow can be passed 'preload: true' but that is not working.

var contactsWindow = Titanium.UI.createWindow({  
    url:'contacts_window.js',
    title:'Contacts',
    backgroundImage:'images/background.png',
    preload: true    
});

My app.js raises an event (after doing a webservice) which I use to initialize the windows in the various tabs of tabgroup. If the windows are not initialized then I believe the event is being ignored and they do not initialize.

How can I solve this issue?

— asked June 4th 2010 by Gaurav Srivastva
  • iphone
  • preload
  • tab
  • window
0 Comments

1 Answer

  • Accepted Answer

    That's true, you won't be able to preload windows assigned to tabs. What you can do is in contacts_window.js fire an event asking for the data you need.

    In app.js:

    // this is the data needed by the other windows
    var webServiceResults = null;
    // ...
    // call web service and store results in variable above
    // ...
    Ti.App.addEventListener("getData", function() {
      Ti.App.fireEvent("sendData", {
        myResult:webServiceResults
      });
    });
    

    and in contacts_window.js or any other tab:

    Ti.App.fireEvent("getData");
    Ti.App.addEventListener("sendData", function(e) {
      // e.myResult contains the result of your web service
      Ti.API.info(e.myResult);
    });
    

    So in this model, your tab asks for the data it needs when it loads, using custom events.

    — answered June 4th 2010 by Kevin Whinnery
    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.