2014-10-10 39 views
0

我有3個屏幕,合金(Appcelerator的):合金導航

INDEX.XML

<Alloy> 
    <Window class="container"> 
     <ImageView id = "actor" image="/images/f_logo.jpg"></ImageView> 
     <Label id = "bienvenue" onClick="doClick" > Bienvenue </Label> 
     <Label id = "apropos"> A propos </Label> 
    </Window> 
</Alloy> 

的welcome.xml

<Alloy> 
    <Window class = "win2container"> 
     <ImageView id = "bienvenue2" image="/images/f_logo.jpg"></ImageView> 
     <View id="texte" onClick="showTable"> 
      <Label text="Afficher la liste" ></Label> 
     </View> 
    </Window> 
</Alloy> 

liste.xml

<Alloy> 
<Tab title="Basic"> 
    <Window title="Basic"> 
     <ListView id = "liste" itemClick="onItemClick"> 
      <ListSection> 
       <ListItem title="Row 1"></ListItem> 
       <ListItem title="Row 2"></ListItem> 
       <ListItem title="Row 3"></ListItem> 
       <ListItem title="Row 4"></ListItem> 
       <ListItem title="Row 5"></ListItem> 
       <ListItem title="Row 6"></ListItem> 
       <ListItem title="Row 7"></ListItem> 
       <ListItem title="Row 8"></ListItem> 
       <ListItem title="Row 9"></ListItem> 
       <ListItem title="Row 10"></ListItem> 
       <ListItem title="Row 11"></ListItem> 
       <ListItem title="Row 12"></ListItem> 
      </ListSection> 
     </ListView> 
    </Window> 
</Tab> 
</Alloy> 

index.js(作品)

function doClick(e) { 
var win = Alloy.createController("welcome").getView(); 
win.open(); 
} 

$.index.open(); 

welcome.js(我想打開窗戶清單當然)

function showTable(e){ 
var liste = Alloy.createController("liste"); 
liste.getView().open(); 
} 

當我的索引標識它打開歡迎窗口點擊當我點擊歡迎視圖時,它什麼也不做,我的目的是發現如何在合金中瀏覽多個窗口(查看文件)。

其次我對谷歌看到,這是一個很好的做法,關閉以前的Windows這樣的:它不

$.win.close(); 
$.win = null; 

當我把這個代碼中index.js後$ .win.open()作品(即:我得到錯誤)

function doClick(e) { 
var win = Alloy.createController("bienvenue").getView(); 
win.open(); 
$.win.close(); // or win.close() ? 
$.win = null; // or win = null ? 
} 

有什麼建議嗎?我嘗試了很多次而沒有成功。

謝謝大家。

回答

1

關於close()是好的做法,是和不是。

如果您希望當用戶使用後退按鈕瀏覽時窗口在那裏,那麼不會,因爲實質上它會被關閉。

function doClick(e) { 
var win = Alloy.createController("bienvenue").getView(); 
    win.open(); 
    $.win.close(); // DEFINITELY $.win, as you created a var named win for your new window 
    $.win = null; // and $.win is the equivalent of findViewById("win") 
} 

順便說一句,你打開窗口的方式,你將無法利用導航(硬件已經回到了Android的,軟靠背中的iOS導航)

有了Android,我通常編寫我自己的經理來確定當前哪個窗口關注焦點,以及當您返回時會發生什麼。

與iOS,你應該使用這樣的事情你的窗口陸續添加到導航部分

var controllerWindow = Alloy.createController("bienvenue") // changed win to controllerWindow for clarity 


var nav = Titanium.UI.iOS.createNavigationWindow({ 
        window: controllerWindow 
       }); 
nav.open(); 
+0

任何知名和經過測試的庫,可以爲我做跨平臺請嗎? – SudoPlz 2015-09-15 15:14:59

0

我相信你以後的答案是如何關閉一個窗口,那裏的行動是從觸發,同時打開一個新的。

你的例子只是創建並打開一個新窗口。然後關閉它。你需要做的是關閉前一個窗口。如果您爲前一個窗口提供了id,則可以用$.id.close()關閉。