How to preload for Windows in tabs

You must Login before you can answer or comment on any questions.

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?

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.

Your Answer

Think you can help? Login to answer this question!