How do you link to pages/windows in Titanium Mobil

2019-04-16 17:00发布

问题:

I realize this is the most basic of questions, but I am unable to find out how to link between windows without using tabs.

The following code works to close a window, which sort of works as a back button. But how do I specify which file/url I would like to link to?

btn_home.addEventListener("click", function() {
Ti.UI.currentWindow.close();
});

I found a solution:

btn_home.addEventListener('click', function() { 
var newWindow = Titanium.UI.createWindow({ url: 'home.js' }); 
newWindow.open(newWindow,{animated:true}); 
});

回答1:

There is a few ways you can do this.

App flow for samples:

  1. app.js opens page1.js
  2. page1.js opens page2.js ( just like the code you have above )

Approaches:

  1. Add a button to the navbar, toolbar or customized view that acts like a "back" button and closes page2.js
  2. Create a window manager through events. This usually sits in the app.js and manages what windows are opened and closed.
  3. Use TabGroups, but hide the TabBar when the window is open by setting tabBarHidden:true. You'll have to do this when opening all windows though.

If you're only building on iOS I'd recommend #3 as it is easiest. If you are also doing Android #2 would provide the greatest amount of flexibility as it allows you to better style the page "header".